Access Control List (ACL): A Guide for File Permissions

Understanding file permissions is central to system administration and security. An Access Control List (ACL) gives you a more fine-grained model than the traditional owner, group and others permissions. This guide shows how to set specific user permissions with ACLs. I ran every command below on a real system, and found that two statements in the first version of this guide were wrong.

What I tested, and what I did not

I used a disposable Ubuntu 24.04 container (no folders from my own computer mounted into it, nothing that changes a real disk) with three accounts: owner, alice and bob. Its filesystem was overlay, and ACLs worked on it. The first version used a user literally named user and a directory named dir, so I replaced those with real accounts. The list of what I did not test is at the end.

In the first versionWhat I found
setfacl -x u:user dir “removes all access rights from user”It removes only that user’s ACL entry. In my test alice could still list the directory and read a file in it, through the “other” permissions
setfacl -m u:user:rw- dir limits the user “to read and write only”On a directory, rw- let alice list names but not open files or create anything, because there is no x
The getfacl dir sample outputIt showed no ACL entries. After setfacl the output has a user: line and a mask:: line
setfacl is availableIt is not installed on a fresh Ubuntu 24.04. Install the acl package

Installing the tools

A fresh Ubuntu 24.04 had no setfacl. The acl package provides setfacl and getfacl:

sudo apt install acl       # Debian/Ubuntu
sudo dnf install acl       # Fedora/RHEL

apt install acl worked and gave setfacl 2.3.2. On Rocky Linux 9 the acl package was not installed either (rpm -q acl said so). I did not run the dnf install. Your filesystem has to support ACLs too. The overlay filesystem in my container did, and I did not test other filesystems.

1. Regular Permissions vs. ACL

Regular permissions are set with chmod. For instance:

chmod u=rwx,g=rx,o=rx dir

This gives the owner read, write and execute, and the group and everyone else read and execute. ACL permissions let you grant access to one specific user (or group) on top of that:

setfacl -m u:alice:rwx dir

This grants the user alice read, write and execute on dir. The user must exist, which is why I use alice here instead of the first version’s literal user. Afterwards, getfacl shows the new entry, and ls -l marks the directory with a +:

# file: dir
# owner: owner
# group: owner
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x

drwxrwxr-x+ 2 owner owner 4096 Nov 25 23:49 dir

As alice, creating a file in the directory worked.

2. Modifying ACL

Use -m again to change an existing entry. The first version’s example:

setfacl -m u:alice:rw- dir

The first version said this limits the user to reading and writing. On a directory, that is not what happens. The x (execute) permission is what lets you enter a directory and reach the files in it. With rw- on my test directory, alice could still list the names, but:

What alice triedResult
ls /tmp/t/dirWorked: it listed the names
cat /tmp/t/dir/note.txtPermission denied
touch /tmp/t/dir/newPermission denied

For a directory, use r-x for read-only access and rwx for full access. rw- is rarely what you want. On a plain file, rw- means exactly what it says.

3. Removing Specific User’s ACL

To remove a user’s entry, use -x:

setfacl -x u:alice dir

The first version said this removes all access rights from the user. It does not. It deletes the ACL entry, and the user is then treated like anyone else, so the “other” permissions apply. My directory’s mode was drwxr-xr-x, so other had read and execute. After the command, alice could still list the directory and read the file in it:

# file: dir
# owner: owner
# group: owner
user::rwx
group::r-x
mask::r-x
other::r-x

alice: ls dir        -> by-alice note.txt
alice: cat dir/note.txt -> secret

To actually keep alice out, give her an explicit entry with no permissions, or tighten the permissions for everyone else:

setfacl -m u:alice:--- dir

With that entry, alice’s ls failed with Permission denied. (chmod o-rwx dir is the other route, which I did not run. setfacl -b removes all ACL entries at once, and I used setfacl -R -b in the backup example below.)

4. Checking ACL Entries

Use getfacl to see the ACL entries:

getfacl dir

On a directory that has no ACL entries, the output is just the basic owner, group and other permissions:

# file: dir
# owner: owner
# group: owner
user::rwx
group::r-x
other::r-x

That is the output the first version showed, and it is what a directory looks like before any setfacl. Once you add an entry, as in section 1, the output gains a user:alice:rwx line and a mask:: line, and ls -l shows a + after the permission string. A + means “this file has ACL entries, so check with getfacl“.

5. The Mask: Why an ACL Entry Sometimes Does Not Apply

When a file has ACL entries it also has a mask, which is the most permissions that any named user or group entry can effectively have. This catches people out because chmod on the group bits changes the mask. I gave alice rwx on a directory with the group bits at rwx, then ran chmod g=rx on it:

user:alice:rwx	#effective:r-x
mask::r-x

getfacl shows alice’s entry as rwx but marks it #effective:r-x, and creating a file as alice failed with Permission denied. Running chmod g=rwx on the directory brought the mask back to rwx and restored the access. If a user’s ACL permission seems to be ignored, look for #effective in the getfacl output.

6. Default ACLs for New Files

Entries you set with -m apply to the file or directory itself. To have new files and subdirectories inherit an entry, set a default ACL on the directory with -d:

setfacl -d -m u:alice:rw proj

getfacl proj then lists default: lines, including default:user:alice:rw-. A file created in that directory afterwards got user:alice:rw- automatically. A new subdirectory got an access entry for alice and the default entries copied into it, so the rule keeps applying further down.

7. Changing, Backing Up and Restoring Many Files

Add -R to apply a change recursively. The capital X is useful here: it gives execute permission only to directories (and files that are already executable), so you do not make every file executable:

setfacl -R -m u:bob:rX tree

In my test this gave bob r-- on the files and r-x on the directories, and bob could read tree/sub/f2. Before bulk changes, save the current ACLs:

getfacl -R tree > acl.bak     # save
setfacl -R -b tree            # remove ALL ACL entries under tree
setfacl --restore=acl.bak     # put them back

After setfacl -R -b, bob got Permission denied again. After --restore, his entry was back and he could read the file. Be careful with -b: it removes every ACL entry, including ones you did not add, so make the backup first.

8. Copying Files: Do ACLs Survive?

A copy does not necessarily keep the ACL. I copied a file that had an entry for bob four ways and counted bob’s entries on each copy:

CommandCopy has bob’s ACL entry?
cp file copyNo
cp -a file copyYes
rsync -a file copyNo
rsync -aA file copyYes (-A preserves ACLs)

If ACLs matter, use cp -a or rsync -aA when you copy or back up. The + in ls -l is a quick check that an ACL came along.

By mastering these commands you can restrict files to the users who need them. Remember that an ACL adds to the normal permissions: the “other” bits, the mask and directory execute permission all still apply.

What I did not test

  • Group entries (setfacl -m g:team:rx), and ACLs on filesystems other than ext4-backed overlay (for example NFS, XFS or tmpfs).
  • The dnf install acl command, ACLs with SELinux, and a real server rather than a container.
  • Everything ran as root inside the container, with su to the test users, on small test files.

Related guides