Access control lists
Grant per-user and default permissions with setfacl beyond owner, group and other.
By Invicly Tech, , in Linux Administration (RHCSA-style). About 10 minutes to read.
In short
Standard permissions allow only one owner and one group. Access control lists add entries for extra named users and groups, and default ACLs on a directory are inherited by new files. A plus sign at the end of ls -l output tells you a file has an ACL.
Explained simply
Normal Linux permissions have room for exactly one owner, one group and everyone else. Real life is messier: you may need the finance group to read a folder, the auditor group too, and one contractor to write to a single file. An access control list (ACL) lets you add such extra entries to a file.
Each extra entry names a user or a group and gives it its own read, write and execute rights. The normal owner, group and others still work as before; ACL entries are added on top.
On a directory you can also set a default ACL. It is not used to check access to the directory itself. Instead it is a template: every new file or folder created inside copies it. That way, access rules apply to future files automatically.
When a file has an ACL, ls -l shows a + after the permission string. That small + is your hint to run getfacl, because ls alone no longer tells the full story.
Press Play on a diagram to walk through it one step at a time.
- Step 1Owner?
Use the user:: entry.
- Step 2Named user?
Use user:name: entry, limited by the mask.
- Step 3Owning or named group?
Group entries, limited by the mask.
- Step 4Otherwise
Use the other:: entry.
- 1user::rw-
Owner, never limited by the mask
- 2user:alice:rw-
Named user, limited by the mask
- 3group::r--
Owning group, limited by the mask
- 4group:audit:r--
Named group, limited by the mask
- 5mask::rw-
Ceiling for the middle entries
- 6other::---
Everyone else, never limited by the mask
In depth
How ACL entries line up with the mode bits
Every file already has a minimal ACL of three entries: user:: (owner), group:: (owning group) and other::. They are simply the normal mode bits seen another way. As soon as you add a named entry, such as user:alice:rw-, the ACL becomes extended and a fourth kind of entry appears: the mask.
Here is the part that confuses people. On a file with an extended ACL, the middle three letters in ls -l show the mask, not the owning group's rights. So chmod g=r on such a file changes the mask, which limits every named user and group, not just the owning group. Always use getfacl to see what is really going on.
- getfacl file shows every entry and the mask
- ls -l shows a + when an extended ACL exists
- setfacl -b file removes all extra entries and the mask
The mask caps everything in the middle
The mask is the most rights that any named user, named group or the owning group can get. Effective rights are the entry ANDed with the mask. The owner and other entries are never limited by it.
setfacl -m recalculates the mask by default so that it covers all entries, which is why things usually just work. The problem comes later: someone runs chmod 640 on the file, the mask becomes r--, and alice's rw- entry is quietly reduced to read only. getfacl shows this with a comment like #effective:r-- next to her entry.
To set the mask on purpose, use setfacl -m m::rw file. To stop setfacl from changing the mask, add -n. A tight mask is a quick way to make all extra entries read-only in one step.
- Step 1Entry user:alice:rw-
What was granted to her
- Step 2mask::r--
Set by a later chmod 640
- Step 3AND them together
Only bits present in both survive
- Step 4Effective r--
alice can read but not write
Default ACLs and inheritance
Default entries exist only on directories and are set with setfacl -d -m or a d: prefix, as in setfacl -m d:g:team:rwX dir. When a file is created inside, its access ACL is copied from the directory's default ACL, then limited by the mode the program asked for (usually 666 for files). That is why new files do not become executable even if the default says rwx.
When a directory has a default ACL, the umask is not applied to new files in it. This makes default ACLs the reliable way to get group-writable files in a shared folder, even for users whose umask is 022. New subdirectories inherit the default ACL as well, so the rule spreads down the tree.
Existing files are never changed. For a complete setup, run the rule twice: once with -R -m for what exists and once with -R -d -m for what is coming.
- New file report.txt
- Access ACL g:team:rw- (no x, file asked for 666)
- New directory data/
- Access ACL g:team:rwx
- Also gets the same default ACL
- Old file notes.txt
- Unchanged, needs setfacl -R -m
Keeping ACLs when you copy, back up and restore
ACLs are stored as extended attributes, and not every tool carries them. cp without options drops them; cp -a or cp --preserve=all keeps them. mv inside one file system keeps them because nothing is copied. tar needs --acls when creating and extracting, and rsync needs -A (usually together with -a).
You can save and restore ACLs as text: getfacl -R /srv/proj > proj.acl writes them all, and setfacl --restore=proj.acl puts them back. ext4 and xfs support ACLs out of the box on RHEL and Ubuntu. NFS version 4 shares use a different ACL model with its own tools, nfs4_getfacl and nfs4_setfacl.
Remove entries with -x for one entry, -k for the default ACL and -b for everything extra.
- rsync -aA src/ dst/ copies files with their ACLs
- tar --acls -czf proj.tgz /srv/proj keeps ACLs in an archive
- setfacl -k dir removes only the default ACL
Learn it in 4 short steps
About 30m each. Track them with a timer in your plan.
- 1Read ACLs with getfacl~30m
- 2Grant a user access with setfacl~30m
- 3Set default ACLs on directories~30m
- 4Understand the ACL mask~30m
Key points
- setfacl -m u:alice:rw file grants alice read and write.
- setfacl -d -m sets default entries that new files in a directory inherit.
- The mask caps the rights of named users and groups; chmod on the group bits changes it.
- setfacl -x removes one entry and -b removes all of them.
Key terms
Tap a card to flip it. 0/5 known
Examples
setfacl -m u:alice:rw /srv/report.csv
setfacl -m g:auditors:r /srv/report.csv
setfacl -d -m g:team:rwx /srv/team # inherited by new files
getfacl /srv/report.csv
ls -l /srv/report.csv # note the + after the mode
setfacl -x u:alice /srv/report.csvGrant, inherit, inspect and remove ACL entries.
Read-only access for a contractor, now and later
Contractor carol must read everything in /srv/proj, including files added next month, but must not join the team group or write anything. Step 1: grant read and directory traversal to existing items with -R and the capital X. Step 2: set the same rule as a default so new items inherit it. Step 3: verify with getfacl. Step 4: test as carol, reading and then trying to write.
sudo setfacl -R -m u:carol:rX /srv/proj
sudo setfacl -R -d -m u:carol:rX /srv/proj
getfacl /srv/proj | grep carol
# user:carol:r-x
# default:user:carol:r-x
sudo -u carol cat /srv/proj/plan.txt > /dev/null && echo can read
sudo -u carol touch /srv/proj/x # Permission deniedThe disappearing write access
alice had write access to budget.xlsx through an ACL. After a colleague tidied permissions with chmod 640, alice can only read. Step 1: getfacl shows her entry still says rw- but a comment says effective r--. Step 2: the mask became r-- because chmod changed the group bits. Step 3: restore the mask with setfacl -m m::rw. Step 4: confirm the effective comment is gone.
getfacl budget.xlsx
# user::rw-
# user:alice:rw- #effective:r--
# group::r--
# mask::r--
# other::---
setfacl -m m::rw budget.xlsx
getfacl budget.xlsx | grep -E 'alice|mask'
# user:alice:rw-
# mask::rw-Quick reference
- setfacl -m u:alice:rw file adds or changes one entry; g:team:r for a group
- setfacl -R -m g:team:rwX dir fixes existing items; add -d for future ones
- With an ACL, the group bits in ls -l show the mask, not the owning group
- setfacl -m m::rw file sets the mask by hand
- setfacl -x u:alice file removes one entry; -b removes all; -k removes defaults
- getfacl -R dir > dir.acl backs up ACLs; setfacl --restore=dir.acl brings them back
- cp -a, rsync -aA and tar --acls keep ACLs; plain cp drops them
Common mistakes
- Running chmod g-w later and silently shrinking the ACL mask.
- Expecting a new default ACL to change existing files; it only applies to files created later.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Give user alice read and write access to /srv/data/report.csv without changing its owner or group, then show the result.
- Exercise 2medium
Set up /srv/shared so that group auditors can read every existing and future file, and group editors can read and write every existing and future file.
- Exercise 3hard
Back up all ACLs under /srv/shared, remove them completely, prove they are gone, and then restore them exactly.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What does the + at the end of the permissions in ls -l mean?
- The file has an extended ACL with entries beyond owner, group and others. Run getfacl on it to see them.
- When should I use an ACL instead of a group?
- Use groups when the same people need the same access to many things. Use ACLs for exceptions, such as one extra user or a second group on a specific folder.
- Do I need to enable ACLs on my file system?
- Not on modern RHEL or Ubuntu with xfs or ext4; ACL support is on by default. Some older systems needed the acl mount option for ext4.
- Why did chmod break my ACL?
- On a file with an extended ACL, chmod's group bits set the mask. Lowering them silently limits every named user and group; fix it with setfacl -m m::rwx.