Linux and servers · Intermediate · 14 min
Grant extra file access with Linux ACLs: setfacl and getfacl
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · acl 2.3.2
You will give one user read access to an app's log directory with an ACL, make new files inherit it, see how the mask and chmod interact, keep ACLs when copying and archiving, and remove them again.
On this page
Classic Linux permissions give a file one owner, one group and everyone else. That covers most cases, until someone needs access that fits none of the three. A support engineer needs to read an app's logs, but adding them to the app's group would also let them read its config and secrets. Changing the group of the log folder could break the app.
An access control list (ACL) solves this by adding extra entries to a file: "this named user may read", "this named group may read and enter". The normal owner, group and other bits stay as they are. Ubuntu's ext4 and XFS filesystems support ACLs out of the box, and the tools are setfacl to change them and getfacl to read them.
In this tutorial you build a small demo under /srv/acl-demo. A service user webapp owns a log directory. You give dana read access to it with an ACL, keep sam locked out, and check every change by running commands as each user with sudo -u. Root ignores permissions, so a check run as root proves nothing.
ACLs are handy on a small shared server too, such as one VPS that a few freelancers or contractors look after: you can give one person read access to one folder without reorganising groups, and take it away again in one command.
Step 1 · Install the tools and build the demo tree
Install the acl package, which provides setfacl and getfacl, and rsync, which you use later. Then create the three users.
sudo apt-get update
sudo apt-get install -y acl rsyncsudo useradd --system --user-group --no-create-home --shell /usr/sbin/nologin webapp
sudo useradd --create-home --shell /bin/bash dana
sudo useradd --create-home --shell /bin/bash samwebapp is a system user with no login shell, the way a service account should be. dana and sam are ordinary users.
Now create the log directory, owned by webapp and closed to everyone else, and have webapp write a log file. Many services that write logs set a umask of 027 (in a systemd unit that is UMask=0027), so their files come out 640: readable by the owner and group, nothing for others. The command below sets that umask itself, so the result does not depend on your shell's setting.
sudo mkdir -p /srv/acl-demo/logs
sudo chown webapp:webapp /srv/acl-demo/logs
sudo chmod 750 /srv/acl-demo/logs
sudo -u webapp sh -c 'umask 027; echo "GET / 200" > /srv/acl-demo/logs/app.log'
sudo ls -l /srv/acl-demo/logsThe redirect sits inside sh -c, so the file is written by webapp, not by your own shell.
Check it worked
Try to read the log as dana:
if sudo -u dana cat /srv/acl-demo/logs/app.log; then echo "unexpected: dana can read the log"; false; fiYou see Permission denied. dana is not the owner, not in the webapp group, and "other" has no access. The listing shows -rw-r----- 1 webapp webapp for app.log.
Step 2 · Give one user read access
setfacl -m (modify) adds an entry. The entry u:dana:rx means "user dana gets read and execute". A directory needs both: r to list the names inside, x to open them. The file only needs r.
sudo setfacl -m u:dana:rx /srv/acl-demo/logs
sudo setfacl -m u:dana:r /srv/acl-demo/logs/app.log
sudo ls -ld /srv/acl-demo/logs
sudo getfacl /srv/acl-demo/logsls -ld now prints drwxr-x---+. The + at the end of the permission string is the only sign in ls -l that a file has an ACL, so look for it whenever permissions behave in a way the nine bits do not explain.
getfacl prints the full list:
# file: srv/acl-demo/logs
# owner: webapp
# group: webapp
user::rwx
user:dana:r-x
group::r-x
mask::r-x
other::---user::, group:: and other:: are the classic three. user:dana: is your new named entry. The mask:: line is the most any named user, named group or the owning group can get; setfacl recalculates it for you, and the next steps show why it matters. getfacl also prints a note that it removed the leading / from the path. That is normal.
Check it worked
Read the log as each user:
sudo -u dana ls /srv/acl-demo/logs
sudo -u dana cat /srv/acl-demo/logs/app.log
if sudo -u dana touch /srv/acl-demo/logs/dana-was-here; then echo "unexpected: dana can write"; false; fi
if sudo -u sam cat /srv/acl-demo/logs/app.log; then echo "unexpected: sam can read the log"; false; fidana lists the folder and sees GET / 200. Her touch fails with Permission denied, because the entry gives no w. sam is still refused. The owner and group of the folder did not change, so webapp works exactly as before.
Step 3 · Make new files inherit the rule
An ACL on a directory does not cover files created later. Have webapp write a second log and try it as dana:
sudo -u webapp sh -c 'umask 027; echo "GET /login 200" > /srv/acl-demo/logs/before.log'
if sudo -u dana cat /srv/acl-demo/logs/before.log; then echo "unexpected: dana can read before.log"; false; fidana is refused. Fix the files that already exist with a recursive change:
sudo setfacl -R -m u:dana:rX /srv/acl-demo/logsCapital X adds execute only to directories and to files that already have an execute bit somewhere in their permissions or ACL. app.log and before.log have none, so dana's entry on them is r--, while the folder keeps r-x.
That fixes today's files, but every log rotation would lock her out again. The answer is a default ACL: entries on a directory that are copied onto every new file and subdirectory created inside it. Set one with -d:
sudo setfacl -d -m u:dana:rx /srv/acl-demo/logs
sudo -u webapp sh -c 'umask 027; echo "GET /health 200" > /srv/acl-demo/logs/after.log'
sudo getfacl /srv/acl-demo/logs/after.logThe new file's ACL includes:
user:dana:r-x #effective:r--
group::r-x #effective:r--
mask::r--Two things happened. The default entries were copied onto after.log, execute bit and all, because the same default serves new subdirectories, which need x. And the mask on the new file is r--, because a log file is created without execute bits, so dana and the webapp group effectively get read only. #effective is how getfacl tells you the mask is cutting an entry down.
Note also that when a directory has a default ACL, the creating process's umask is ignored for new files in it; the default ACL decides instead. Here the default other::--- keeps others out, which is what you want.
Those hidden x bits are a trap for the next recursive change. X sees that after.log already has x in its ACL, so sudo setfacl -R -m <entry>:rX would give the new entry x there. setfacl then works the mask out again as the union of the named entries and group::, which is r-x, and ls -l would show -rw-r-x---+: the webapp group and dana would effectively get execute on a log file. Two ways to avoid it: add -n, which tells setfacl to leave the mask alone, or put the file masks back afterwards with sudo find /srv/acl-demo/logs -type f -exec setfacl -m m::r {} +. Re-running with m::rX does not help, because X sees the same x bits. You use -n in the group step later on.
Check it worked
sudo -u dana cat /srv/acl-demo/logs/before.log
sudo -u dana cat /srv/acl-demo/logs/after.log
if sudo -u sam cat /srv/acl-demo/logs/after.log; then echo "unexpected: sam can read after.log"; false; fi
sudo getfacl /srv/acl-demo/logs | grep '^default:user:dana:r-x'
sudo ls -l /srv/acl-demo/logs
for f in app.log before.log after.log; do test "$(sudo stat -c %A /srv/acl-demo/logs/$f)" = "-rw-r-----" || { echo "unexpected mode on $f"; false; }; donedana reads both files, sam reads neither, and the grep prints default:user:dana:r-x, the inherited rule. In the listing, app.log, before.log and after.log all show -rw-r-----+, owned by webapp webapp: nothing became executable, and the + marks each file's ACL. The last line checks those modes and prints nothing when they are right.
Step 4 · Understand the mask and what chmod does to it
On a file with an ACL, the middle three bits that ls -l shows are no longer the owning group's permissions. They are the mask. So a chmod that changes the group bits changes the mask, and the mask limits every named entry.
Say someone tightens the folder with a familiar command:
sudo chmod 700 /srv/acl-demo/logs
sudo getfacl /srv/acl-demo/logsThe access part of the output now reads:
user:dana:r-x #effective:---
group::r-x #effective:---
mask::---dana's entry is still there, but the mask is ---, so she gets nothing. This catches people out: the ACL looks right, yet access fails.
Check it worked
Confirm dana is locked out, then restore the mask and confirm she is back:
if sudo -u dana ls /srv/acl-demo/logs; then echo "unexpected: the mask did not block dana"; false; fi
sudo setfacl -m m::rx /srv/acl-demo/logs
sudo -u dana ls /srv/acl-demo/logsThe first ls fails with Permission denied; after setfacl -m m::rx it lists after.log, app.log and before.log. sudo chmod 750 would have restored it too, because it sets the mask back to r-x. When a folder has a + in ls -l, check getfacl before and after any chmod.
Step 5 · Copy and archive without losing ACLs
Many copy tools drop ACLs unless you ask for them. That matters for backups and migrations: a restored folder can look correct in ls -l and still lock people out.
cp keeps ACLs only when it preserves modes, as cp -a and cp -p do. Compare a plain copy with cp -a:
sudo cp /srv/acl-demo/logs/app.log /srv/acl-demo/plain-copy.log
sudo cp -a /srv/acl-demo/logs /srv/acl-demo/cp-copytar needs --acls both when creating and when extracting:
sudo tar --acls -cpf /srv/acl-demo/logs.tar -C /srv/acl-demo logs
sudo mkdir -p /srv/acl-demo/restore
sudo tar --acls -xpf /srv/acl-demo/logs.tar -C /srv/acl-demo/restorersync needs -A alongside -a, and the destination filesystem must support ACLs too:
sudo rsync -aA /srv/acl-demo/logs/ /srv/acl-demo/rsync-copy/Check it worked
Look for dana's entry in each copy:
if sudo getfacl /srv/acl-demo/plain-copy.log | grep -q 'user:dana'; then echo "unexpected: plain cp kept the ACL"; false; fi
sudo getfacl /srv/acl-demo/cp-copy/app.log | grep 'user:dana'
sudo getfacl /srv/acl-demo/restore/logs/app.log | grep 'user:dana'
sudo getfacl /srv/acl-demo/rsync-copy/app.log | grep 'user:dana'
sudo -u dana cat /srv/acl-demo/rsync-copy/after.logThe plain copy has no dana entry. The cp -a, tar --acls and rsync -aA copies each print user:dana:r--, and dana can read the rsync copy.
Step 6 · Remove ACL entries
There are three removal options, from narrow to broad:
setfacl -x u:dana <path>removes one named entry.setfacl -k <dir>removes the default ACL from a directory, so new files stop inheriting.setfacl -b <path>removes every ACL entry and leaves only the classic bits.
Take dana's access away from the restored copy entry by entry, then strip the rsync copy completely:
sudo setfacl -x u:dana /srv/acl-demo/restore/logs/app.log
sudo setfacl -k /srv/acl-demo/restore/logs
sudo setfacl -R -b /srv/acl-demo/rsync-copy
sudo ls -l /srv/acl-demo/rsync-copyCheck it worked
if sudo getfacl /srv/acl-demo/restore/logs/app.log | grep -q 'user:dana'; then echo "unexpected: the dana entry is still there"; false; fi
if sudo getfacl /srv/acl-demo/restore/logs | grep -q '^default:'; then echo "unexpected: the default ACL is still there"; false; fi
if sudo -u dana cat /srv/acl-demo/rsync-copy/app.log; then echo "unexpected: dana can still read the stripped copy"; false; fiAll three checks pass quietly, apart from the Permission denied from the last one. The ls -l listing of the stripped copy shows no + on any file.
Step 7 · Use a group when more people need the same access
One named user in an ACL is easy to follow. Five named users across a tree is not: every new person means another recursive setfacl, and removing someone means finding every place they were added. When more than one or two people need the same access, create a group for the job, put one group entry in the ACL, and manage membership with usermod.
Give a new logreaders group read access to the original log folder, with a default entry so new logs follow, and add sam to it:
sudo groupadd logreaders
sudo setfacl -R -n -m g:logreaders:rX /srv/acl-demo/logs
sudo setfacl -d -m g:logreaders:rx /srv/acl-demo/logs
sudo usermod -aG logreaders samThe -n on the recursive command is the guard from the default ACL step: without it, X would give logreaders x on after.log and the recalculated mask would widen to r-x. Every file here already has the mask you want (r-x on the folder, r-- on the logs), so leaving it alone is safe. On a file whose mask is narrower than the new entry, -n would cut the entry down, so check with getfacl afterwards.
From now on, giving someone log access is sudo usermod -aG logreaders <user>, and taking it away is sudo gpasswd -d <user> logreaders. Replace <user> with the real account name.
Ask whether you need an ACL at all. If the files can simply belong to a group that only the right people are in (for example, the app writes its logs with the group logreaders), plain chown and chmod do the job and nobody has to remember the +. ACLs earn their place when the owning group must stay as it is.
Check it worked
sudo -u sam cat /srv/acl-demo/logs/after.log
sudo getfacl /srv/acl-demo/logs | grep '^group:logreaders:r-x'
sudo ls -l /srv/acl-demo/logs
test "$(sudo stat -c %A /srv/acl-demo/logs/after.log)" = "-rw-r-----" || { echo "unexpected: after.log mode changed"; false; }sam now reads the log, and the listing still shows -rw-r-----+ for all three logs. sudo -u picks up the new group straight away; a user who is already logged in over SSH needs to log out and back in first, and id sam shows the groups a new session will get.
Step 8 · Clean up the demo
The next commands delete /srv/acl-demo and the three demo users with their home folders. Check the names before you run them, so you do not remove a real account or folder that happens to share a name.
sudo rm -rf /srv/acl-demo
sudo userdel -r dana
sudo userdel -r sam
sudo userdel webapp
sudo groupdel logreadersuserdel webapp also removes the webapp group, because it was created with --user-group and has no other members. userdel may print a note that a user's mail spool was not found; that is harmless.
Check it worked
for u in dana sam webapp; do if getent passwd "$u"; then echo "unexpected: $u still exists"; false; fi; done
if getent group logreaders; then echo "unexpected: logreaders still exists"; false; fi
test ! -e /srv/acl-demo && echo "demo removed"The script prints demo removed and nothing about leftover users or groups.
Next steps
- Go back over the classic modes,
umaskand the setgid bit in /tutorials/linux-file-permissions-chmod-chown. - Set up a service account with its own directories, the kind of owner you gave
/srv/acl-demo/logshere, in /tutorials/give-a-service-its-own-system-user-and-directories. - Read
man 5 aclon the server for the exact rules the kernel uses to pick which entry applies.
Related tutorials
- Write safer Bash scripts with strict mode and trapsYou will build a small Bash release script that stops on the first error, says which line failed, survives file names with spaces and always removes its temporary files.
- Write least-privilege sudo rules with visudoYou will replace blanket sudo access with checked rule files in /etc/sudoers.d that let two operators restart one service and edit one file, give an automation account a password-free command list, and audit what every account can run.
- Upgrade a server from Ubuntu 24.04 LTS to 26.04 LTSYou will take a backed-up Ubuntu 24.04 server through do-release-upgrade to 26.04 LTS over SSH with a fallback login, then confirm services, repositories and language runtimes work on the new release.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials