Exploring Linux ACLs: From Basics to Best Practices

Updated

Linux ACLs Guide: Enhance File Security Effortlessly

An access control list (ACL) adds per-user and per-group permissions on top of owner, group and other. setfacl -m u:alice:rw file grants alice read and write, getfacl file lists every entry, and a + after the permission bits in ls -l flags a file that has one.

The “acsls” in the URL is not ACSLS, Oracle’s tape library software; this page covers Linux ACLs.

The four commands you will use most

These four commands cover most of what follows, with username standing in for a real account:

setfacl -m u:username:rw file.txt   # grant one user read+write
getfacl file.txt                    # list a file's ACL entries
setfacl -x u:username file.txt      # remove that user's entry
setfacl -d -m u:username:rwx dir/   # default ACL: files created in dir/ inherit it

Read a file’s ACL with getfacl

A file has one user owner and one group owner at a time (Red Hat, RHEL 8). A new file has only the three base entries:

$ touch report.txt

$ ls -l report.txt
-rw-r--r-- 1 alice alice 0 Oct  6 14:42 report.txt

$ getfacl report.txt
# file: report.txt
# owner: alice
# group: alice
user::rw-
group::r--
other::r--

user::, group:: and other:: are the base entries (setfacl(1)). --omit-header drops the three comment lines on top (getfacl(1)). There is no + after the mode yet: ls -l adds one once a file has more than these three entries (acl(5)).

Give a second user access with setfacl

setfacl -m u:nobody:rw adds a named entry for the user nobody. I ran it as an unprivileged account on its own file: the owner may change a file’s ACL, so root is not needed (setfacl(1)).

$ setfacl -m u:nobody:rw report.txt

$ ls -l report.txt
-rw-rw-r--+ 1 alice alice 0 Oct  6 14:42 report.txt

$ getfacl report.txt
# file: report.txt
# owner: alice
# group: alice
user::rw-
user:nobody:rw-
group::r--
mask::rw-
other::r--

The + has appeared. The middle rw- in ls -l is the mask, not the group (group::r-- is unchanged): once a mask entry exists, the group bits show the mask (acl(5)).

I put this step in a script you can run: acsls-permissions-guide.sh grants your own account rw on a scratch file and checks that getfacl lists the entry, and on a Mac it runs the chmod +a examples below.

How the mask limits effective permissions

The mask caps every named user, named group and the owning group (acl(5)). With the mask set to read-only, nobody’s rw- entry stays on file but getfacl marks it #effective:r--:

$ setfacl -m m::r report.txt

$ getfacl report.txt
# file: report.txt
# owner: alice
# group: alice
user::rw-
user:nobody:rw-	#effective:r--
group::r--
mask::r--
other::r--

chmod edits the mask too (my chmod permissions calculator converts between symbolic and octal modes): with a mask present the group bits are the mask, so chmod g+w set mask::rw- and nobody’s effective access went back to rw-:

$ chmod g+w report.txt

$ getfacl --omit-header report.txt
user::rw-
user:nobody:rw-
group::r--
mask::rw-
other::r--

group::r-- never changed. Red Hat warns about the opposite case: chmod g-w tightens the mask and can block users you authorized (Red Hat, RHEL 8).

Remove one ACL entry or all of them

-x removes one entry. setfacl then recalculates the mask unless you pass -n or give a mask entry in the same command (setfacl(1)), so the mask fell back to r--, the owning group’s permission:

$ setfacl -x u:nobody report.txt

$ getfacl --omit-header report.txt
user::rw-
group::r--
mask::r--
other::r--

-b removes every extended entry, mask included, and leaves only the three base entries (setfacl(1)). I ran this one later in the session, when report.txt had a read-only entry for nobody. The + leaves ls -l:

$ setfacl -b report.txt; ls -l report.txt; getfacl --omit-header report.txt
-rw-r--r-- 1 alice alice 0 Oct  6 14:42 report.txt
user::rw-
group::r--
other::r--

Set a default ACL on a shared directory

A directory’s default ACL becomes the initial access ACL of everything created in it later (acl(5)). -d edits the default ACL, and X grants execute only on directories and on files that already have it (setfacl(1)), so here the entry was stored as rwx:

$ mkdir shared

$ setfacl -d -m u:nobody:rwX shared

$ getfacl --omit-header shared
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:nobody:rwx
default:group::r-x
default:mask::rwx
default:other::r-x

setfacl added the other default entries itself (setfacl(1)). A new file and a new subdirectory:

$ touch shared/new.txt && mkdir shared/sub

$ getfacl --omit-header shared/new.txt
user::rw-
user:nobody:rwx	#effective:rw-
group::r-x	#effective:r--
mask::rw-
other::r--

The file inherited nobody’s rwx, but nobody’s effective access is rw-. Files are created without execute permission (Red Hat), and the creation mode caps the inherited entries, which gives mask::rw-. With a default ACL the umask is not applied; it matters only when the directory has none (acl(5)). The subdirectory:

$ getfacl --omit-header shared/sub
user::rwx
user:nobody:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:nobody:rwx
default:group::r-x
default:mask::rwx
default:other::r-x

The subdirectory keeps the entries as its access ACL and its own default ACL, so inheritance continues down the tree. Existing files keep their ACLs; -R applies an entry to a whole tree (setfacl(1)).

Copy files without losing their ACLs

cp dropped nobody’s entry and cp -a kept it. --omit-header removes the file names, so the first block is copy-plain.txt and the second is copy-a.txt:

$ setfacl -m u:nobody:r report.txt

$ cp report.txt copy-plain.txt; cp -a report.txt copy-a.txt; getfacl --omit-header copy-plain.txt copy-a.txt
user::rw-
group::r--
other::r--

user::rw-
user:nobody:r--
group::r--
mask::r--
other::r--

cp -p preserves ACLs and mv always does (acl(5)), and Red Hat’s RHEL 7 guide lists cp -a too (Red Hat, RHEL 7). rsync -a does not keep ACLs and needs -A (rsync(1)); my rsync backup guide lists what else -a omits.

Back up and restore ACLs with getfacl

getfacl -R prints the ACLs of a whole tree and setfacl --restore reads them back (setfacl(1)). I saved the ACLs of shared to a file, stripped them with setfacl -R -b, and checked that new.txt had lost its entries:

$ getfacl -R shared > acls.txt; setfacl -R -b shared; getfacl --omit-header shared/new.txt
user::rw-
group::r--
other::r--

I ran the restore in the same directory as the backup. setfacl warned and restored the entries anyway:

$ setfacl --restore=acls.txt; getfacl --omit-header shared/new.txt
Warning: option --restore=file is unsafe without option -P (--physical) as it traverses symbolic links in pathnames
user::rw-
user:nobody:rwx	#effective:rw-
group::r-x	#effective:r--
mask::rw-
other::r--

The warning is that --restore is unsafe without -P because it follows symbolic links in pathnames. setfacl(1) allows -P with --restore; I did not run that form. A restore also resets the owner, group and setuid, setgid and sticky bits from the backup (setfacl(1)).

Keep ACLs inside a tar archive

Red Hat says to pass --acls to tar when archiving to preserve ACLs (Red Hat, RHEL 7). Each member in this listing shows a + after its mode:

$ tar --acls -cf demo.tar shared && tar --acls -tvf demo.tar | head -3
drwxr-xr-x+ alice/alice       0 2026-10-06 14:42 shared/
drwxrwxr-x+ alice/alice       0 2026-10-06 14:42 shared/sub/
-rw-rw-r--+ alice/alice       0 2026-10-06 14:42 shared/new.txt

I only listed the archive and did not extract it; listing first is the habit my guide to extracting tar archives recommends.

Best practices for Linux ACLs

  • Prefer one group entry to many user entries. This is my rule of thumb, built on two documented facts: access checks test a process’s supplementary groups against group entries (acl(5)), and Red Hat describes adding a user to a supplementary group as a way to enable access to certain files and removing the user to limit it (Red Hat). setfacl -m g:team:rw file then covers the whole group (setfacl(1)). Avoid denying access by group: acl(5) calls that bad practice.
  • Use default ACLs on shared directories. They set the initial ACL of everything created there (acl(5)), so new files arrive with the right entries.
  • Mind the mask. On a file with an ACL, chmod changes the mask, and the #effective comments show the permissions actually enforced (Red Hat, RHEL 8), so run getfacl after any chmod.
  • Audit with getfacl -R. getfacl -R dir lists every ACL under dir, and -s skips files with only the base entries (getfacl(1)).
  • Assume copies and backups drop ACLs until you have checked. Plain cp lost the entry above; cp -p and mv keep ACLs (acl(5)), and Red Hat says to pass --acls to tar (Red Hat, RHEL 7).

Use ACLs on macOS with chmod +a

macOS 26.6 has no setfacl or getfacl. chmod +a adds an entry and ls -le lists them (Apple’s chmod man page source, Apple’s ls man page source). My account name is replaced with [user] in the output:

$ chmod +a "staff allow read,write" f.txt
$ ls -le f.txt
-rw-r--r--@ 1 [user]  staff  6 Aug 12 00:08 f.txt
 0: group:staff allow read,write

On a directory, file_inherit and directory_inherit are the closest counterpart to a default ACL: new items pick the entry up, and macOS marks the child’s copy inherited:

$ chmod +a "staff allow read,write,file_inherit,directory_inherit" sub
$ touch sub/child.txt && ls -le sub/child.txt
-rw-r--r--@ 1 [user]  staff  0 Aug 12 00:08 sub/child.txt
 0: group:staff inherited allow read,write

Why ls -l can hide a macOS ACL behind @

On macOS ls -l prints @ when a file has extended attributes and a + only when it has none (Apple’s ls man page source), so the first block above shows @ although the entry is there: a file I create in a shell on my Mac carries com.apple.provenance. Two folders in my home directory show the effect:

drwx------@  6 [user]  staff  192 May 25 10:00 Desktop     # ACL present, but an xattr hides the "+"
drwx------+ 18 [user]  staff  576 May 24 21:05 Documents   # ACL present, no xattr — "+" shows

Both carry a group:everyone deny delete entry. As of 6 October 2026 both show @, because Documents has gained an extended attribute too, yet ls -le still lists the entry on each. Run ls -le instead of trusting the +; my troubleshooting and optimization guide shows a deny entry beating chmod 777.

Tested on: the Linux commands on 6 October 2026 on an Enterprise Linux 8 server (acl-2.4.0-1.el8_10, ext4, unprivileged user, nobody as the second account), with the owner and group name in the output replaced by alice, and the macOS commands on macOS 26.6 (MacBook Pro, Apple M3 Max), where the output blocks were captured earlier and the commands re-run that day. Not tested: access as the second account itself, other distributions or filesystems, group entries, getfacl -s, setfacl -R -m, cp -p, mv, rsync, restoring with -P and extracting the tar archive, which rest on the cited man pages and Red Hat guides.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.