ITNuvoAkademiya
Academy homePackagesPlaylistsToolsSubnet calculatorSearchGlossary
CiscoCCNA · CCNA: networking fundamentals1. Introduction2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise networks · coming soon
LinuxLinux: system administrator üçün · Linux for system administrators1. Getting to know Linux2. Working with text3. Users and permissions4. Processes and packages5. Inside the system6. Monitoring and logs7. NetworkingRed Hat Enterprise Linux · Red Hat Enterprise Linux: from beginner to advanced1. Getting started2. Packages3. Users and permissions4. SELinux5. Services6. Storage7. Networking8. Building services9. Boot and recovery10. DevOps11. Security and monitoring
FortinetFortiGate Administrator · FortiGate Administrator: from first login to ZTNA1. Getting to know FortiGate2. Routing, policy and NAT3. Security profiles4. Users and logs5. Resilience, SD-WAN and automation6. VDOM7. VPN and ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: from installation to alerts1. Introduction2. Installation and the database3. Basics: groups, templates, users4. Connecting devices5. Alerts, Grafana and the API
VirtualizationProxmox VE · coming soonVMware ESXi · coming soon
My account / Sign in
AZENRU
← itnuvo.com

ACL: setfacl, getfacl

Lesson 3.57 minIntermediateDecember 1, 2026
Open

This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.

Key points

  • setfacl -m u:name:rx file gives a user permissions, -m g:group:rw a group; getfacl file shows them all.
  • A + in ls -l means the file has an ACL; in that case the group column is actually the mask.
  • setfacl -m d:g:group:rwx dir — a default ACL: inherited automatically by new files in the directory.
  • setfacl -x u:name removes one entry, setfacl -b removes all; -R for a directory.
  • XFS and ext4 support ACLs by default; cp -a and tar --acls keep them.

The problem

The /srv/share directory belongs to the wheel group (previous lesson). Now:

  • ali is not a wheel member but must read the reports in the directory;
  • the audit group must read too;
  • others must see nothing.

Standard permissions cannot do this — a file has only one group. The solution is ACLs.

Setting an ACL

srv-web01
[ali@srv-web01 ~]$ sudo setfacl -m u:ali:rx /srv/share
[ali@srv-web01 ~]$ sudo setfacl -m g:audit:rx /srv/share
[ali@srv-web01 ~]$ ls -ld /srv/share
drwxrws---+ 2 root wheel 32 Dec  1 12:50 /srv/share
[ali@srv-web01 ~]$ getfacl /srv/share
# file: srv/share
# owner: root
# group: wheel
# flags: -s-
user::rwx
user:ali:r-x
group::rwx
group:audit:r-x
mask::rwx
other::---

Reading the output:

LineMeaning
user::rwxThe owner's (root) permissions
user:ali:r-xAn ACL entry for the named user ali
group::rwxThe file's own group (wheel)
group:audit:r-xThe named group audit
mask::rwxThe maximum permission for named entries and the group
other::---Others
flags: -s-The SGID bit

A + appeared at the end in ls -l — the file has an ACL.

The mask: a hidden limit

The mask is the maximum permission that can be given to named users and groups. On a file with an ACL, the group column of ls -l actually shows the mask. If you run chmod g-w, the mask changes and everyone's effective permission drops:

srv-web01
[ali@srv-web01 ~]$ sudo setfacl -m u:leyla:rwx /srv/share
[ali@srv-web01 ~]$ sudo chmod g=rx /srv/share
[ali@srv-web01 ~]$ getfacl /srv/share | grep -E "leyla|mask"
user:leyla:rwx			#effective:r-x
mask::r-x

#effective:r-x — leyla was given rwx, but because the mask is r-x the real permission is r-x. Remember the rule: be careful with chmod on files that have ACLs. To restore the mask: setfacl -m m::rwx /srv/share.

Default ACL: for new files

A normal ACL applies only to the existing file. For it to pass automatically to files created later in the directory, a default (d:) ACL is needed:

srv-web01
[ali@srv-web01 ~]$ sudo setfacl -m d:g:wheel:rwx,d:u:ali:rx,d:o::- /srv/share
[ali@srv-web01 ~]$ sudo -u ops1 touch /srv/share/yeni.txt
[ali@srv-web01 ~]$ getfacl /srv/share/yeni.txt
# file: srv/share/yeni.txt
# owner: ops1
# group: wheel
user::rw-
user:ali:r-x			#effective:r--
group::rwx			#effective:rw-
group:wheel:rwx			#effective:rw-
mask::rw-
other::---

Now wheel members can edit each other's files (regardless of umask), and ali only reads. x is not effective on files — a new file gets no execute permission by default, which is correct.

This is the cleanest solution to the previous lesson's "the team should edit each other's files" problem.

Management commands

CommandWhat it does
setfacl -m u:name:rw fileAdd or change
setfacl -m g:group:r fileFor a group
setfacl -m d:u:name:rx dirDefault ACL
setfacl -x u:name fileRemove one entry
setfacl -k dirRemove only the default ACL
setfacl -b fileRemove the whole ACL
setfacl -R -m g:audit:rX dirFor all existing files (X — x only for directories)
getfacl -R dir > acl.txtBackup
setfacl --restore=acl.txtRestore

Careful with backups: plain cp and tar can lose ACLs. Use cp -a and tar --acls --xattrs.

Lab: read access for an auditor

Finish the "A shared directory: SGID and ACL" task in the Red Hat simulator:

  1. Give ali read and traverse access only on /srv/share.
  2. Check with getfacl.
srv-web01
[ali@srv-web01 ~]$ sudo setfacl -m u:ali:rx /srv/share
[ali@srv-web01 ~]$ getfacl /srv/share | grep ali
user:ali:r-x
[ali@srv-web01 ~]$ ls -ld /srv/share
drwxrws---+ 2 root wheel 6 Dec  1 12:50 /srv/share
  1. (On your own VM) set a default ACL for wheel, create files as two different users and try to write to each other's file — it should work.
  2. (On your own VM) run chmod g=r /srv/share and see how the #effective column changes in getfacl. Then restore with setfacl -m m::rwx.

Check: in the simulator both conditions of the task are green; ls -ld shows a +.

Check yourself

5 questions · answers are shown instantly · 3 correct answers complete the lesson

1Which command gives the user ali read-only access to a file?

-m (modify) adds an entry.

2What does a + at the end of the permissions in ls -l mean?

Look in detail with getfacl.

3getfacl shows user:leyla:rwx #effective:r-x. Why?

The mask is the maximum for named entries.

4What is needed for an ACL to pass automatically to files created in a directory in the future?

-R applies only to files that exist now.

5Which command is right for copying files together with their ACLs?

tar needs the --acls option.
Was this lesson useful?

Comments

Sign in to comment.