About ACLs (Access Control Lists)
The getfacl (get file access control list) and setfacl (set file access control list) commands manage POSIX Access Control Lists, which extend beyond traditional Unix permissions (owner/group/other). ACLs allow you to grant specific permissions to specific users and groups, providing much more granular control over file and directory access.
Traditional Permissions Limitations:
- Standard Unix: owner, group, other (3 permission sets)
- Problem: What if you need to grant access to 5 different users with different permission levels?
- Solution: ACLs allow unlimited users and groups with specific permissions
Key Concepts:
- getfacl: Displays ACLs for files and directories
- setfacl: Sets or modifies ACLs
- Access ACLs: Control access to the file/directory itself
- Default ACLs: Apply to new files created in a directory (directories only)
- Mask: Defines maximum permissions for named users/groups
- Effective Permissions: Actual permissions = ACL entry AND mask
Common Use Cases:
- Multi-user collaboration with different permission levels
- Shared directories requiring complex access patterns
- Web server directories with multiple application users
- Database directories with separate backup user access
- Project directories with team-specific permissions
- Drop boxes where users can write but not read others' files
| Entry Type | Format | Description |
|---|---|---|
| User (owner) | user::rwx |
Permissions for the file owner |
| Named user | user:username:rwx |
Permissions for a specific user |
| Group (owning) | group::rwx |
Permissions for the owning group |
| Named group | group:groupname:rwx |
Permissions for a specific group |
| Mask | mask::rwx |
Maximum effective permissions for named users/groups |
| Other | other::rwx |
Permissions for everyone else |
| Option | Description |
|---|---|
-m |
Modify ACL - add or change entries |
-x |
Remove specific ACL entries |
-b |
Remove all ACL entries (keep base permissions) |
-k |
Remove default ACL entries |
-d |
Set default ACL (for directories) |
-R |
Recursive - apply to directory tree |
--set |
Replace entire ACL (not merge) |
--set-file |
Read ACL entries from file |
--restore |
Restore ACLs from getfacl output |
Example 1View Current ACLs
Display ACLs for a file to see current permissions:
Explanation:
getfacl: Displays ACL for file- Comments (# lines): Show file, owner, group
user::: Owner permissions (rw-)group::: Group permissions (r--)other::: World permissions (r--)- No extended ACLs yet - just standard permissions
- Matches what
ls -lshows
getfacl shows the same information as traditional Unix permissions. The power comes when you add additional users and groups beyond the basic owner/group/other model.
Example 2Grant Access to Additional User
Give specific user read access without changing group or other permissions:
Explanation:
-m user:alice:r--: Grant alice read permission- Note the '+' in
ls -l: indicates extended ACL user:alice:r--: Alice can read the filemask::r--: Auto-created, limits max permissions- Group and other still have no access
- Only craig (owner) and alice can access this file
ls -l output is your quick indicator that a file has extended ACLs. Always check getfacl to see the full picture when you see that plus sign.
Example 3Grant Access to Multiple Users
Give different permissions to several specific users:
Explanation:
- Multiple
setfacl -mcommands add entries - alice: Full access (rwx)
- bob: Read and execute (r-x) - can list and enter
- charlie: Read only (r--) - can list but not enter
mask::rwx: Allows up to full permissions- Each user has exactly the access they need
setfacl commands can be combined: setfacl -m user:alice:rwx,user:bob:r-x,user:charlie:r-- shared-project/ achieves the same result in one command.
Example 4Default ACLs for New Files
Set default ACLs so new files automatically inherit permissions:
Explanation:
-d: Sets default ACL (directories only)- Default ACLs shown with "default:" prefix
- New files automatically inherit these permissions
- alice automatically gets rw- on new files
- bob automatically gets r-- on new files
- No need to set ACLs on each new file
Example 5Grant Access to Groups
Give permissions to entire groups rather than individual users:
Explanation:
group:analysts:r-x: All analysts can read/listgroup:managers:rwx: Managers have full access- Any user in 'analysts' group gets read access
- Any user in 'managers' group gets full access
- Cleaner than listing individual users
- Easier maintenance - add users to groups, not ACLs
Example 6Understanding the Mask
The mask limits maximum effective permissions for named users/groups:
Explanation:
- alice granted rwx permissions
- Initial mask is rwx (allows full permissions)
chmod g-wremoves group write, affects mask- Mask becomes r-- (read only)
- alice's effective permissions: rwx AND r-- = r--
- Mask provides safety limit on ACL permissions
chmod on files with ACLs, you're actually modifying the mask, which affects all named users and groups. Use setfacl -m mask::rwx to explicitly set the mask.
Example 7Remove Specific ACL Entries
Remove ACL entries for specific users or groups:
Explanation:
-x user:bob: Remove ACL entry for bob- bob's entry is completely removed
- alice and charlie entries remain
- bob now has only "other" permissions
- Use
-xto revoke specific access - Can also remove group entries:
-x group:groupname
setfacl -x user:alice,user:bob,group:staff file. Comma-separate entries for batch removal.
Example 8Remove All ACLs
Strip all extended ACLs and return to basic permissions:
Explanation:
-b: Remove all ACL entries- '+' disappears from
ls -loutput - Only base permissions remain (owner/group/other)
- alice, bob, and staff lose special access
- Returns file to traditional permission model
- Useful for cleanup or troubleshooting
setfacl -b removes ALL extended ACLs immediately. This is permanent and cannot be undone. Consider backing up ACLs first: getfacl file > file.acl.backup before using -b.
Example 9Backup and Restore ACLs
Save ACLs to file and restore them later:
Explanation:
getfacl -R: Backup all ACLs recursively- Output saved to text file
--restore: Restore ACLs from file- All ACLs restored exactly as saved
- Essential for disaster recovery
- Useful for cloning ACLs to similar directories
getfacl -R /data > /backup/acls-$(date +%Y%m%d).txt. When restoring from backup, you'll need both the files AND their ACLs to restore complete access control.
Example 10Recursive ACL Application
Apply ACLs to entire directory tree at once:
Explanation:
-R: Apply ACLs recursively to all files/dirs- webuser gets r-x on whole tree (read/execute)
- webuser gets rw- on logs/ and data/ (read/write)
-d: Set default ACLs for new files- New files in logs/ will auto-get rw- for webuser
- Perfect for web application directories
Setting ACL permissions that are restricted by the mask without realizing it.
Solution: Always check getfacl output for "#effective:" comments. If permissions don't work as expected, explicitly set mask: setfacl -m mask::rwx file. Remember: effective permissions = ACL entry AND mask.
Setting ACLs on directory but not default ACLs - new files don't inherit permissions.
Solution: For directories, always set both access AND default ACLs: setfacl -m user:alice:rwx dir/ && setfacl -d -m user:alice:rw- dir/. Default ACLs determine what new files inherit.
Many backup tools (rsync, tar) don't preserve ACLs by default.
Solution: Use ACL-aware options: rsync -A, tar --acls, cp --preserve=all. Or backup ACLs separately: getfacl -R / > /backup/all-acls.txt. Test restore procedures!
NFS, FAT32, some network mounts don't support ACLs.
Solution: Check filesystem: mount | grep acl. ext4, XFS, Btrfs support ACLs. Some need mount option: mount -o acl. NFSv4 has different ACL system. For unsupported filesystems, use groups and traditional permissions.
Using chmod on ACL-enabled files changes the mask, affecting multiple users.
Solution: Understand that chmod group permissions modify the mask. To change only base permissions without affecting mask: remove ACLs first, chmod, re-add ACLs. Or use setfacl exclusively.
Adding too many individual user ACLs becomes unmaintainable.
Solution: Use groups! Create groups for roles (developers, analysts, viewers) and grant ACLs to groups, not individuals. Much easier to manage. Keep it simple - if you have >10 ACL entries per file, rethink your design.
Verify ACLs work as intended:
Actually testing as the user reveals mask issues and unexpected restrictions.
Create README files explaining ACL structure:
Helps future administrators understand the design.
Regularly review ACLs for unexpected changes:
Catches unauthorized ACL modifications. Compare with previous audits.
ACLs and MAC systems work together (defense in depth):
ACLs control discretionary access, SELinux controls mandatory access.
Clone ACL structure to similar directories:
Pipe getfacl output directly to setfacl for quick cloning. Great for creating similar project directories.
Track who modifies ACLs:
Security monitoring - alerts when ACLs are changed.
| Task | Command |
|---|---|
| View ACLs | getfacl file |
| Grant user access | setfacl -m user:username:rwx file |
| Grant group access | setfacl -m group:groupname:rx file |
| Remove user ACL | setfacl -x user:username file |
| Remove all ACLs | setfacl -b file |
| Set default ACL | setfacl -d -m user:username:rwx directory/ |
| Recursive ACLs | setfacl -R -m user:username:rx directory/ |
| Backup ACLs | getfacl -R directory/ > backup.acl |
| Restore ACLs | setfacl --restore=backup.acl |
| Set mask explicitly | setfacl -m mask::rwx file |
| Multiple entries | setfacl -m user:alice:rwx,user:bob:rx file |
Ready-to-Use ACL Patterns
| Scenario | Command Template |
|---|---|
| Shared project directory | setfacl -m user:user1:rwx,user:user2:rx dir/ |
| Drop box (write-only) | setfacl -m user:dropuser:-wx dir/ |
| Read-only for group | setfacl -R -m group:readers:r-x dir/ |
| Web application dir | setfacl -R -m user:www-data:rwx /var/www/app/ |
| Backup user access | setfacl -R -m user:backup:r-x /data/ |
| Multi-tier access | setfacl -m user:admin:rwx,group:editors:rw-,group:viewers:r-- dir/ |