Beginner · Permissions, users and sudo · topic 11 of 57 · 25 min
Access control lists (ACLs)
Explanation
The problem ACLs solve
The finance directory belongs to the finance group. Now the auditor, who is not in finance, needs to READ it for a month, and the HR group needs read access to one file. With only owner, group and others you cannot express this without opening the file to everyone. An ACL lets you add exact extra rules.
Reading and setting ACLs
# setfacl -m u:iyer:rx /srv/finance # user iyer: read + enter
# setfacl -m g:hr:r /srv/finance/salaries.csv # group hr: read this file
# getfacl /srv/finance
# file: srv/finance
# owner: root
# group: finance
user::rwx
user:iyer:r-x
group::rwx
mask::rwx
other::---
$ ls -ld /srv/finance
drwxrwx---+ 2 root finance 26 Oct 19 13:00 /srv/financeThe mask
The mask entry is the maximum that named users, named groups and the owning group can get. If the mask is r--, then user:iyer:rwx actually works as r-- (getfacl shows #effective:r--). chmod on a file with an ACL changes the mask when you change the group digits, which can quietly reduce what ACL users get. Check getfacl after a chmod.
Default ACLs for new files
An ACL on a directory does not apply to files created later. For that, set a default ACL (d:) on the directory. New files and subdirectories inherit it. Usually you set both: one for what exists now (with -R) and a default for the future.
# setfacl -R -m u:iyer:rX /srv/finance # existing files and dirs (X = x only on dirs)
# setfacl -m d:u:iyer:rx /srv/finance # default for new files
# setfacl -x u:iyer /srv/finance # remove one entry
# setfacl -b /srv/finance # remove all ACL entries
# getfacl /srv/finance > finance.acl # back up ACLs
# setfacl --restore=finance.acl # restore them| Option | Meaning |
|---|---|
| -m | Modify / add entries, e.g. u:name:rw, g:name:r |
| -x | Remove an entry |
| -b | Remove all extended entries |
| -R | Recursive |
| d: | Prefix that makes a default (inherited) entry |
Common mistakes
- Setting only a default ACL and wondering why the user cannot open existing files. Defaults apply to NEW files only; also run setfacl -R -m.
- Forgetting x on the directories in the path. iyer needs at least x on /srv as well.
- Copying files with plain cp, which drops ACLs. Use cp -a or tar with --acls when ACLs matter.
- Ignoring the mask: if an entry does not work, look for #effective in getfacl.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Access control lists (ACLs) · 1/6
Normal permissions allow one owner and one group. ACLs add extra named users and groups.
Prefer a video by a teacher? Find free videos on “linux acl setfacl getfacl tutorial rhcsa” on YouTube ↗
In real life: Giving a CA firm read access for the annual audit
A Chennai manufacturing company hires an external chartered accountant firm for its audit. The CA's account must read the ledgers for six weeks without joining the finance group. The admin adds an ACL entry with read access and a default entry for new files, sets the account to expire after six weeks, and removes the ACL with setfacl -x when the audit ends.
# useradd -e 2026-12-15 ca_auditor
# setfacl -R -m u:ca_auditor:rX /srv/ledgers
# setfacl -m d:u:ca_auditor:rX /srv/ledgers
# getfacl -c /srv/ledgers | grep ca_
user:ca_auditor:r-x
default:user:ca_auditor:r-xPractice (0/3 done)
What does the + in drwxr-x---+ mean?
Which command gives user ravi read and write on report.txt without changing the owner or group?
Copy /etc/fstab to /var/tmp/fstab. Make it owned by root with mode 644. Then use ACLs so that user "natasha" can read and write it, user "harry" can neither read nor write it, and everyone else can still read it.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- sudo and the sudoers filePermissions, users and sudo · same module
- Access control lists (ACLs)Computer Networking (CCNA level) · Network security
- Users, groups and permissionsDevOps: Git, Docker, Kubernetes and CI/CD · Linux for DevOps
- Subnet masks, prefix length and wildcard masksComputer Networking (CCNA level) · IPv4 addressing
- Linux basics for backend developersBackend Development · Deployment and scaling
- Securing and sharing S3 dataCloud Computing (AWS, Azure, Google Cloud) · Compute and storage: EC2 and S3
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which command shows the ACL of a file?
Answer: getfacl
getfacl prints all ACL entries.
What does setfacl -m d:g:dev:rwx /srv/code do?
Answer: Sets a default ACL so new files give group dev rwx
d: makes a default entry that new files inherit.
An ACL says user:ravi:rw- but getfacl shows #effective:r--. Why?
Answer: The mask is r--
The mask limits named entries.
Which removes every ACL entry from a file?
Answer: setfacl -b file
-b removes all extended entries.
Which command shows how many packets matched each ACL rule?Related
Answer: show access-lists
show access-lists prints each rule with its matches counter.
A file is owned by asha with mode 604 (rw----r--). asha is also in the file's group. Can asha read it?Related
Answer: Yes, as owner
The owner set rw- applies to asha, so she can read and write.
On a directory, what does the x permission allow?Related
Answer: Entering the directory with cd
For directories, x means you may enter (traverse) it.
What is the dotted decimal mask for /27?Related
Answer: 255.255.255.224
/27 = 24 + 3: three ones in the last octet = 128 + 64 + 32 = 224.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “Permissions, users and sudo” before its exam: sudo and the sudoers file.
- Module 2 exam: Permissions, users and sudo · 14 questions · 25 min, without help. 6 topics of this module still to finish first.
- Then the next module, Processes, services and logs. 57 topics left in the course before the final exam.
← Previous: umask and the special bits: SUID, SGID and sticky