الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

setfacl

Add, change or remove ACL entries: rights for extra users and groups on files and directories.

المستوى
لينكس اليومي
المجموعة
الصلاحيات
يحتاج root
للتغييرات
الحزمة
acl

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Normal permissions have one owner and one group. With setfacl you add more: u:carol:rx for a user, g:account:rwx for a group. A default ACL (-d) on a directory is copied to new files and directories in it.

The mask is the maximum for all named users and groups and the owning group. setfacl sets it automatically; chmod g=... on a file with an ACL changes the mask.

Only the owner or root may change an ACL. XFS and ext4 on RHEL support ACLs without extra mount options.

طريقة الكتابة

setfacl [-bkndRLPvh] [{-m|-x} ACL] [{-M|-X} FILE] FILE...
setfacl --set=ACL FILE...
setfacl --restore=FILE

الأجزاء الرئيسية

u:USER:PERMS
Rights for a named user (u::PERMS = the owner).
g:GROUP:PERMS
Rights for a named group (g::PERMS = the owning group).
m::PERMS
The mask.
o::PERMS
Others.
d:ENTRY
A default entry (same as -d).
PERMS
r, w, x, X (x only for folders) or - ; numbers 0–7 work too.

الخيارات 18

الأكثر استخدامًا

-m, --modify=ACL
Add or change entries.
-M, --modify-file=FILE
Read the entries to change from a file (- = stdin).
-x, --remove=ACL
Remove entries (without the rights part, like u:carol).
-X, --remove-file=FILE
Read the entries to remove from a file.
-b, --remove-all
Remove all extra entries (normal mode stays).
-k, --remove-default
Remove the default ACL.
-d, --default
Work on the default ACL.
-R, --recursive
Work on the whole tree.
--set=ACL
Replace the whole ACL.
--set-file=FILE
Replace the whole ACL from a file.
-n, --no-mask
Do not recalculate the mask.
--mask
Recalculate the mask.
--restore=FILE
Restore ACLs from a getfacl -R dump.
--test
Show the result but change nothing.
-L, --logical
Follow links to directories.
-P, --physical
Do not follow links.
-v, --version
Show the version.
-h, --help
Show help.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Give one user read access

    setfacl -m u:carol:r report.txt

    carol may read; the normal mode stays.

  2. 2Give a group full access to a folder

    setfacl -m g:account:rwx /srv/sales

    A second team without changing the owning group.

  3. 3Make new files inherit the rights

    setfacl -d -m g:account:rwX /srv/sales

    Without -d only existing entries change.

  4. 4Existing files and new files together

    setfacl -R -m g:account:rX /srv/sales
    setfacl -d -m g:account:rX /srv/sales

    First the tree, then the default for later files.

  5. 5Remove one entry

    setfacl -x u:carol report.txt

    Only carol's entry goes.

  6. 6Remove all ACLs

    setfacl -R -b /srv/sales

    Back to the normal permissions.

  7. 7Let a service read a log folder

    setfacl -R -m u:promtail:rX /var/log/httpd
    setfacl -d -m u:promtail:rX /var/log/httpd

    A log shipper reads logs without being root or in the group (least privilege).

  8. 8Let a user only pass through a folder

    setfacl -m u:carol:x /home/lisa

    carol can reach a file inside (if she may read it) but cannot list the folder.

  9. 9Test before you change

    setfacl --test -m u:carol:rw report.txt

    Shows the new ACL only.

  10. 10Restore a backup of ACLs

    setfacl --restore=/root/srv-acl.txt

    The dump from getfacl -R.

  11. 11Fix rights cut by the mask

    setfacl -m m::rwx /srv/sales/plan.txt

    The mask limits named entries; set it back to rwx.

انتبه

  • The mask limits named users and groups. Check #effective: in getfacl.
  • A default ACL on a folder replaces the umask for new files there.
  • Backups need ACL support: tar --acls, rsync -A.

رموز الخروج

0 :: Done. 1 :: Error.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man setfacl