Skip to content

POSIX file ACLs on Linux: grant per-user access with setfacl and getfacl

Use setfacl and getfacl to give several users and services different access to one directory tree — including POSIX ACL default entries, the mask, and which copy tools preserve ACLs.

When two services need different levels of access to the same directory tree, plain chmod runs out of room fast: a file has exactly one owner, one group, and one everybody-else. POSIX file ACLs add named entries on top of that model. setfacl -m u:deploy:rwx /srv/app/shared gives one user write access without changing the owner, inventing a group, or falling back to chmod 777; setfacl -d -m u:deploy:rwx /srv/app/shared makes every file created there afterwards inherit it. This guide covers reading getfacl field by field, setting access and default entries, applying them across an existing tree, and the mask entry that quietly strips permissions the moment someone runs chmod.

What you’ll accomplish

  • Confirm the filesystem supports ACLs, and read every field of getfacl output.
  • Grant a named user and a named group access to one directory without a new group or a world-writable mode.
  • Make new files and subdirectories inherit that access using default ACLs.
  • Diagnose the mask, and the chmod interaction that silently removes access.
  • Back up, restore, and copy ACLs without losing them in transit.

Prerequisites

  • A Linux host with the acl package, which provides setfacl and getfacl and is usually absent from minimal container images: apt install acl on Debian/Ubuntu, dnf install acl on RHEL, Rocky, and Alma.
  • root or sudo. Setting an ACL requires ownership of the file or the CAP_FOWNER capability.
  • A filesystem that stores POSIX ACLs. XFS supports them unconditionally, and current distributions build ext4 and Btrfs with ACL support and mount them enabled — only older systems needed an explicit acl mount option. vfat, exfat, and NTFS do not support them at all, and NFS is a separate model — see NFSv4 ACLs and permissions.
  • The examples use a service account deploy and a group web, on the directory /srv/app/shared. Substitute your own; creating those accounts is covered in Linux user and group management.

How it works

A POSIX ACL is a list of entries stored in a filesystem extended attribute. Three are mandatory and map directly onto the classic mode bits: user:: is the owner, group:: is the owning group, other:: is everyone else. A file with no ACL still has exactly those three — getfacl shows them even on a file you have never touched with setfacl.

What ACLs add is named entries: user:deploy:rwx and group:web:r-x. As soon as one exists, the kernel also stores a mask:: entry and the ACL becomes “extended”. Permission checks then walk the entries in a fixed order and stop at the first match.

Decision flow showing how the kernel checks owner, then named user, then group entries, then other, and which of those the mask caps

The mask is the part that surprises people. It is a ceiling, not a grant: the effective permission of a named entry, or of group::, is that entry’s own bits AND the mask, and getfacl flags anything the mask removes with an #effective: annotation. The mask is also what ls -l prints in the group column of an ACL-bearing file, which is why a directory can read as drwxrwx--- while group:: is only r-x. Critically, chmod g+rw on a file with an extended ACL rewrites the mask, not group:: — so a routine chmod can revoke access across every named entry at once.

The second half is inheritance. Access entries apply to the object they are set on and nothing else. For new files to pick up permissions, a directory needs a default ACL — a second, separate list copied into every file and subdirectory created inside it.

Side-by-side comparison of a directory with only an access ACL versus one that also carries default entries, and the resulting new file in each case

Default entries never grant access themselves; they are a template. When a process creates a file, the kernel copies the parent’s default ACL into the new file’s access ACL, then intersects the base entries with the mode the process asked for (0666 for touch, 0777 for mkdir) — the umask is ignored entirely. A subdirectory receives both the access ACL and a copy of the default ACL, so inheritance keeps propagating down the tree.

Step-by-step

1. Confirm ACLs are actually available. Check that the tools exist and see what the filesystem is mounted with:

setfacl --version
findmnt -no FSTYPE,OPTIONS /srv
setfacl 2.3.2
ext4 rw,relatime

The absence of acl in the option list is not a failure — on ext4 it is the compiled-in default and is not printed. Confirm the on-disk default instead, then test for real:

tune2fs -l /dev/vda2 | grep 'Default mount options'
touch /srv/acltest && setfacl -m u:nobody:r /srv/acltest && rm /srv/acltest
Default mount options:    user_xattr acl

The setfacl line printing nothing is the success signal. If it fails with Operation not supported, remount with mount -o remount,acl /srv and add acl to that entry’s options in /etc/fstab.

2. Read the starting point. Create the directory and look at the ACL before changing anything:

mkdir -p /srv/app/shared
chown root:staff /srv/app/shared
chmod 750 /srv/app/shared
getfacl /srv/app/shared
# file: srv/app/shared
# owner: root
# group: staff
user::rwx
group::r-x
other::---

The three comment lines are the header; the three entries are the mode bits restated in ACL syntax. There is no mask:: line yet, because no named entry exists.

3. Grant a named user and a named group. -m modifies the access ACL, using specs of the form type:name:permissions where type is u, g, m, or o:

setfacl -m u:deploy:rwx,g:web:r-x /srv/app/shared
getfacl /srv/app/shared
# file: srv/app/shared
# owner: root
# group: staff
user::rwx
user:deploy:rwx
group::r-x
group:web:r-x
mask::rwx
other::---

Two things happened unasked. A mask::rwx entry appeared — setfacl recalculates it as the union of the named entries and group:: on every modification, unless you pass -n. And the base entries are untouched, which is the point: deploy got write access and nobody else’s access changed.

4. Notice what ls -l now shows. The trailing + is how you spot an extended ACL at a glance:

ls -ld /srv/app/shared
drwxrwx---+ 2 root staff 4096 Jul 28 10:12 /srv/app/shared

The group column reads rwx, but group:: is still r-x. What you are looking at is the mask. Any audit script reading mode bits from ls or stat on a + file sees the ceiling, not the grant — confirm with getfacl.

5. Add default entries so new files inherit. -d makes every -m in that invocation apply to the default ACL instead of the access ACL:

setfacl -d -m u:deploy:rwx,g:web:r-x /srv/app/shared
getfacl /srv/app/shared
# file: srv/app/shared
# owner: root
# group: staff
user::rwx
user:deploy:rwx
group::r-x
group:web:r-x
mask::rwx
other::---
default:user::rwx
default:user:deploy:rwx
default:group::r-x
default:group:web:r-x
default:mask::rwx
default:other::---

setfacl filled in default:user::, default:group::, and default:other:: from the access ACL, because a default ACL is only valid if it is complete. The d: prefix on a spec does the same job as the -d flag — setfacl -m d:u:deploy:rwx is identical — and it is the only way to set access and default entries in one command.

6. Watch inheritance happen. Create a file and read its ACL:

touch /srv/app/shared/release.log
getfacl /srv/app/shared/release.log
# file: srv/app/shared/release.log
# owner: root
# group: staff
user::rw-
user:deploy:rwx			#effective:rw-
group::r-x			#effective:r--
group:web:r-x			#effective:r--
mask::rw-
other::---

The named entries came from the parent’s default ACL. The mask came out rw- rather than rwx because touch asked for mode 0666 and the kernel intersected the default mask with the group bits of that request. That is correct — a file created by touch should not be executable — and the #effective: lines say exactly which bits were dropped.

7. Apply to an existing tree with -R and capital X. Files that already existed when you set the default ACL inherited nothing — defaults act at creation time only. Recursion fixes that, but lowercase x would make every config and log file executable:

setfacl -R -m u:deploy:rwX -m d:u:deploy:rwX /srv/app/shared
getfacl /srv/app/shared/release.log | grep deploy
user:deploy:rw-

Capital X grants execute only on directories and on files that already have an execute bit set for somebody, so release.log ends up rw- while the directories get rwx. The d: prefix on the second -m is what covers both lists in one pass; -d would have skipped the access entries.

8. Remove entries selectively, or wipe them. -x deletes an entry and takes no permission field:

setfacl -x g:web -x d:g:web /srv/app/shared
getfacl /srv/app/shared | grep web

Nothing is printed — both entries for web are gone. Two blunter tools exist: -k removes the entire default ACL and leaves the access ACL alone, and -b removes every extended entry from both lists, leaving only the three base entries:

setfacl -b /srv/app/shared/release.log
ls -l /srv/app/shared/release.log
-rw-r----- 1 root staff 0 Jul 28 10:14 /srv/app/shared/release.log

The + is gone, so the file is back to plain mode bits. To preview any of this before committing, setfacl --test prints the ACL a command would produce without writing anything.

9. Back up the ACLs before you need them. getfacl -R walks a tree and emits a restorable dump; -p keeps paths absolute so the restore does not depend on your working directory:

getfacl -R -p /srv/app/shared > /root/shared-acls.txt
head -4 /root/shared-acls.txt
# file: /srv/app/shared
# owner: root
# group: staff
user::rwx

Without -p, getfacl strips the initial / from every path, and setfacl --restore would then resolve those paths relative to your working directory. Restoring prints nothing on success, and also restores owner and group from the header lines, so run it as root:

setfacl --restore=/root/shared-acls.txt

Validate it works

Check the entries survived and no mask is eating them. A recursive getfacl piped through grep should find no annotations at all:

getfacl -R /srv/app/shared | grep '#effective'

No output means the mask is trimming nothing on the files that exist today. Every line that does appear names a file where a permission you granted is not the permission in force.

Prove it from the account that matters. Reading the ACL is not the same as exercising it:

sudo -u deploy touch /srv/app/shared/probe && echo "deploy can write"
sudo -u deploy cat /srv/app/shared/probe && echo "deploy can read"
deploy can write
deploy can read

Confirm inheritance, and that everyone else is still shut out. The probe file should carry the named entry with no further action, and an account outside the ACL should be refused — that pair is what distinguishes a correct ACL from chmod 777:

getfacl /srv/app/shared/probe | grep '^user:deploy'
sudo -u nobody ls /srv/app/shared
user:deploy:rwx			#effective:rw-
ls: cannot open directory '/srv/app/shared': Permission denied

The #effective:rw- on the inherited entry is expected, not a fault: touch asked for mode 0666, so the new file’s mask has no execute bit to hand out.

Troubleshooting

  • setfacl: Option -m: Invalid argument near character 3. The name in the spec does not resolve, or the spec is malformed — a stray comma, a missing colon, or a group name used with the u: type. Confirm the identity with id deploy and getent group web. If the account only exists inside a container, use the numeric ID: setfacl -m u:1001:rwx /srv/app/shared. ACLs store numeric IDs, so a name that resolves differently elsewhere shows up differently in getfacl too.
  • setfacl: /srv/app/shared: Operation not supported. The filesystem is not carrying ACLs. Check what it is with findmnt -no FSTYPE,OPTIONS /srv. On ext4 mounted noacl, remount with mount -o remount,acl /srv and fix /etc/fstab so it survives a reboot. On vfat, exfat, or NTFS there is no fix — those formats have nowhere to store the entries.
  • The entry is right there in getfacl, and access is still denied. Two causes, in this order. First, look for #effective: on the entry: the mask is capping it, usually because someone ran chmod after the ACL was set. Raise it with setfacl -m m::rwx /srv/app/shared, or re-apply the named entry, since setfacl recalculates the mask by default. Second, check traversal: a user needs execute on every directory in the path, and namei -l /srv/app/shared/release.log prints the mode of each component. If both look right, the denial comes from another layer — see troubleshooting SELinux permission denied.
  • The default ACL is set, but existing files are still unreachable. Default entries apply at creation time only; they are never retroactive. Run the recursive form from step 7 once to bring the current tree in line. Use capital X, not x — if you already ran -R with lowercase x, remove the entry with setfacl -R -x u:deploy /srv/app/shared and re-apply it correctly.
  • ACLs vanish somewhere between two machines. Most transports drop them silently. cp needs -a or --preserve=all, rsync needs -A (or --acls), and tar needs --acls on both create and extract. Plain scp, zip, git, docker cp, and nearly every graphical SFTP client carry only the mode bits. Verify with getfacl on the destination, and keep the getfacl -R -p dump from step 9 as the thing you re-apply on the far side.

When this is the wrong approach

POSIX ACLs are a precision tool for a handful of exceptions. They are a poor substitute for a permission model.

  • If several identities need the same access, create a group. A group is one object to audit, it shows up in id, and every tool on the system understands it. A dozen user: entries scattered across a tree is an unreviewable configuration, and every filesystem caps how many entries one ACL can hold — you will hit that ceiling long before the configuration becomes readable again.
  • They are not NFSv4 ACLs. The two models have different entry types, different inheritance rules, and different tooling. Setting POSIX ACLs on a local directory that is also exported over NFSv4 does not produce the behaviour you expect on the client. Read NFSv4 ACLs and permissions before mixing them.
  • They are not a boundary against root, and not tenant isolation. ACLs constrain unprivileged processes on one host. Workloads that genuinely must not see each other need separate hosts, namespaces, or mandatory access control — SELinux and AppArmor evaluate independently and will deny access the ACL permits.
  • They do not travel with your application. ACLs live in filesystem extended attributes, not in your repository or container image. Image layers, docker cp, and most build pipelines drop them, and UID remapping in rootless containers breaks named entries outright. If a directory’s permissions matter, put them in configuration management that re-applies them on every deploy.

The authoritative references are the setfacl manual page, which specifies the ACL entry syntax and every flag exactly, and acl(5), which documents the access check algorithm and default ACL inheritance.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.