08. Access Control Lists
Standard Linux permissions (User, Group, Others) are often too rigid for complex environments. For example, what if you need to give User A Read/Write access, and User B Read-Only access, but neither user is the owner, and they don’t share a group?
This is where Access Control Lists (ACL) come in.
08.1 What is an ACL?
Section titled “08.1 What is an ACL?”An ACL provides a fine-grained permission mechanism for file systems. It allows administrators to assign specific permissions to multiple arbitrary users or groups beyond the standard UGO (User, Group, Others) triad.
When a file or directory has an active ACL applied to it, a + symbol appears at the end of its permission string when running ls -l (e.g., -rw-rwxr--+).
08.2 Managing ACLs
Section titled “08.2 Managing ACLs”To view and modify ACLs, Linux provides two primary utilities: getfacl and setfacl.
getfacl (Get File ACL)
Section titled “getfacl (Get File ACL)”Reads and displays the ACL entries for a file or directory:
getfacl secret_data.txtExample Output:
# owner: root# group: rootuser::rw-user:alice:rw- <-- ACL entry specifically for Alicegroup::r--mask::rw-other::r--setfacl (Set File ACL)
Section titled “setfacl (Set File ACL)”Modifies, adds, or removes ACL entries:
# Give a specific user (alice) Read and Write permissionssudo setfacl -m u:alice:rw secret_data.txt
# Give a specific group (devs) Read and Execute permissionssudo setfacl -m g:devs:rx /app/scripts/
# Apply ACL recursively across an entire directory tree (-R)sudo setfacl -R -m g:devs:rwx /srv/shared/
# Remove a specific user's ACL entry (-x)sudo setfacl -x u:alice secret_data.txt
# Remove ALL ACL entries from a file (revert to standard POSIX permissions)sudo setfacl -b secret_data.txt08.3 Masks and Default ACLs
Section titled “08.3 Masks and Default ACLs”The ACL Mask
Section titled “The ACL Mask”The mask acts as a ceiling or maximum allowable permission for all ACL users and groups (except the file owner).
If you set the mask to Read-Only (r--), even if you grant alice Read/Write (rw-) via an ACL, her effective permissions are capped at Read-Only:
# Set the maximum allowed ACL permissions to Read and Executesudo setfacl -m m::rx secret_data.txtDefault ACLs (Inheritance)
Section titled “Default ACLs (Inheritance)”Standard Linux permissions do not have true inheritance; a new file uses the process umask rather than inheriting the parent directory’s mode.
Default ACLs (-d) provide true directory inheritance. When applied to a directory, any new file or subdirectory created inside it automatically inherits those ACL rules:
# Add a Default ACL (-d flag) giving the 'devs' group Read/Write accesssudo setfacl -d -m g:devs:rw /app/shared_data/08.4 Enterprise Workflow Example
Section titled “08.4 Enterprise Workflow Example”A common scenario in enterprise operations is provisioning a department-shared directory where team members require collaborative Read/Write access while maintaining base ownership:
# 1. Create the departmental shared directorysudo mkdir -p /finance
# 2. Grant accounting group full read, write, and execute permissionssudo setfacl -m g:accounting:rwx /finance
# 3. Configure default ACLs so all newly created files inherit accounting accesssudo setfacl -d -m g:accounting:rwx /finance
# 4. Verify the active configurationgetfacl /financeVerification output:
# file: finance# owner: root# group: rootuser::rwxgroup::r-xgroup:accounting:rwxmask::rwxother::r-xdefault:user::rwxdefault:group::r-xdefault:group:accounting:rwxdefault:mask::rwxdefault:other::r-xKey Architectural Benefits
Section titled “Key Architectural Benefits”- Multi-User/Group Flexibility: Assign discrete access tiers without cluttering system
/etc/groupdefinitions. - Preserves Base Security: Leaves base user and group ownership intact.
- Automated Inheritance: Eliminates permission breakage when multiple services or team members create files in shared storage.
08.5 Linux Access Control Summary
Section titled “08.5 Linux Access Control Summary”| Mechanism | Purpose | Scope | Primary Tools |
|---|---|---|---|
| UGO Permissions | Basic file access (Owner, Group, Others) | Standard 3-class access | chmod, chown, chgrp |
| Umask | Controls default permissions for newly created files/directories | Session / System-wide creation filter | umask |
| Special Permissions | Privilege escalation (SUID) and group/delete control (SGID, Sticky) | Process execution & directory behavior | chmod 4755, chmod 2770, chmod 1777 |
| ACLs | Granular multi-user and multi-group permissions with inheritance | Filesystem-level extended access | getfacl, setfacl |
08.6 Troubleshooting & Permission Pitfalls
Section titled “08.6 Troubleshooting & Permission Pitfalls”When debugging “Permission Denied” errors, always follow structured diagnostic steps:
ACL Troubleshooting
Section titled “ACL Troubleshooting”- Inspect for the
+indicator: Ifls -lshows-rwxr-xr-x+, standardchmoddoes not represent total permissions. Rungetfaclto view all active rules. - Mask conflicts: If an ACL user cannot write despite having
rw-, check themaskline ingetfacl. When restricted, an effective notation like#effective:r--indicates mask throttling. - Filesystem Support: While modern ext4 and XFS enable ACLs by default, legacy filesystems may require the
aclmount option in/etc/fstab.
Common Permission Pitfalls
Section titled “Common Permission Pitfalls”chmod 777as a quick fix: Never apply777. Identify the exact execution user or group and assign specific rights withchownorsetfacl.- Root-owned volume mounts in Docker: Host paths bind-mounted into containers retain host UID/GID ownership. If owned by
root:root, non-root container processes will crash with permission errors. - Directory Traversal: Accessing a file requires Execute (
x) permissions on the containing directory and all ancestor directories up to/.