setfacl in Linux: Give Specific Users and Groups Access to Files
How to use setfacl and getfacl in Linux: give one more user or group access to a file or folder, set defaults for new files, understand the mask, and remove ACLs.
3 min readBy Smita
Reviewed by the AmazingRDP technical team

Several people working on one server? A Linux VPS gives you root access to set up users and shared folders. See Linux VPS from $6.99
Normal Linux permissions know three parties: the owner of a file, one group, and everybody else. That is not enough when a second group needs to read a folder, or one extra person needs to write to a file. Access control lists (ACLs) add entries for any number of users and groups. setfacl sets them and getfacl shows them.
Check that the tools are there
sudo apt install acl
On Fedora, AlmaLinux and Rocky Linux the package has the same name: sudo dnf install acl. The file systems ext4, XFS and Btrfs support ACLs without any setting.
See the current permissions
getfacl report.txt
The output lists the owner, the group and one line per entry. A file with an ACL shows a + after its permissions in ls -l, for example -rw-rw-r--+.
Give a user or a group access
setfacl -m u:alex:rw report.txt
setfacl -m g:editors:rx /srv/docs
-m means modify. The entry has three parts: u for a user or g for a group, the name, and the rights (r read, w write, x execute, or open in the case of a folder). Several entries go in one command, separated by commas:
setfacl -m u:alex:rw,u:sam:r,g:editors:rw report.txt
A whole folder tree
setfacl -R -m g:editors:rwX /srv/docs
-R applies the entry to everything inside. The capital X gives the execute right only to folders (and to files that are already executable), so that ordinary files do not become programs.
Defaults for new files
Entries set as above apply to what exists now. A default ACL on a folder is copied to every file and folder created in it later:
setfacl -d -m g:editors:rwX /srv/docs
For a shared folder you normally want both commands: the recursive one for existing content and the default one for new content.
The mask
An ACL has a line called mask. It is the upper limit for all named users, the group and named groups; rights above it are listed and not effective. getfacl shows this with a comment such as #effective:r--. The trap: chmod g-w on a file with an ACL lowers the mask and quietly takes write access away from every ACL entry. Set it back with:
setfacl -m m::rw report.txt
Remove entries
| Command | Removes |
|---|---|
setfacl -x u:alex report.txt | One entry |
setfacl -b report.txt | The whole ACL |
setfacl -k /srv/docs | The default ACL of a folder |
setfacl -R -b /srv/docs | All ACLs in a tree |
Copy, save and restore
getfacl report.txt | setfacl --set-file=- copy.txt
getfacl -R /srv/docs > docs-acl.txt
setfacl --restore=docs-acl.txt
The first line copies the ACL of one file to another. The second saves all ACLs of a tree to a text file; the third puts them back, which is useful before a risky change. When copying files, cp -a and rsync -A keep ACLs; plain cp does not.
Example: a shared project folder
sudo mkdir -p /srv/project
sudo chgrp editors /srv/project
sudo chmod 2770 /srv/project
sudo setfacl -m g:reviewers:rX /srv/project
sudo setfacl -d -m g:editors:rwX,g:reviewers:rX /srv/project
Members of editors can read and write, members of reviewers can only read, nobody else gets in, and new files keep these rules. The 2 in 2770 makes new files belong to the group editors.
When not to use ACLs
If one group covers everybody who needs access, plain chown and chmod are simpler and easier to read later. ACLs are for the cases they cannot express.
For a server to practise on, see our Linux VPS plans. Related: grant su or sudo access in Ubuntu, Samba on Ubuntu and mount and automount drives in Linux.
Questions
What does setfacl do?
It sets access control lists: extra permission entries for specific users and groups on a file or folder.
How do I see the ACL of a file?
Run getfacl followed by the file name. A + in ls -l shows that a file has one.
What is a default ACL?
An ACL on a folder that new files and folders created inside it receive automatically. Set it with setfacl -d.
How do I remove an ACL?
setfacl -x removes one entry and setfacl -b removes the whole ACL.