Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

setfacl

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

Level
Everyday Linux
Group
Permissions
Needs root
For changes
Package
acl

What it does

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.

How to write it

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

Main parts

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.

Options 18

Most used

-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.

Examples 11

$ run as a normal user# run as root (or with 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.

Watch out

  • 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.

Exit codes

0Done.
1Error.