POSIX permissions only support one owner, one group, and 'others'. But real-world file servers need Finance to read, HR to modify, and Auditors to have read-only—all on the same directory. Access Control Lists (ACLs) provide that granularity. This lesson equips you to wield Windows icacls and Linux setfacl/getfacl to create layered, auditable file access rules that survive security audits.
Every securable object in Windows has a security descriptor containing a Discretionary ACL (DACL) and System ACL (SACL). The DACL holds Access Control Entries (ACEs) that allow or deny access to users/groups. SACL controls auditing. Using icacls, you can backup, restore, and script complex ACLs. Understanding the order of ACE evaluation (explicit deny, then explicit allow, then inherited) prevents misconfigurations.
The /t switch recurses, and the backup file can be restored with icacls /restore. This is invaluable before making bulk permission changes.
# Use PowerShell to get and set ACLs more programmatically
$acl = Get-Acl -Path "D:\Shared"
$acl.Access | Format-Table IdentityReference, FileSystemRights, AccessControlType💡 Always use 'icacls /verify' after setting permissions to ensure the ACL was applied correctly. It checks consistency of the file system metadata.
Modern Linux filesystems (ext4, xfs) support POSIX ACLs via the acl package. getfacl displays the ACL, including the traditional permission mask and any named user/group entries. setfacl -m adds entries, -x removes them. The mask entry limits the effective permissions of named groups and the owning group. It's the most confusing part: setting a named group rwx, but the mask is r--, the effective permission is r--.
Here, finance gets r-x, audit gets r--, and the mask restricts the effective permissions. The 'mask' is automatically recalculated to the union of all group permissions, but can be manually set to limit.
| Command | Purpose | Example |
|---|---|---|
| getfacl | Display ACL | getfacl /etc/secret |
| setfacl -m | Modify/add entry | setfacl -m u:john:rw /file |
| setfacl -x | Remove entry | setfacl -x g:tempgroup /file |
| setfacl -b | Remove all ACLs | setfacl -b /file (reverts to POSIX only) |
Setting a 'default' ACL on a directory causes new files and subdirectories to inherit that ACL. This is analogous to Windows inheritance. Without default ACLs, new files get only the standard POSIX permissions. Use setfacl -d to define defaults. This is essential for directories where multiple groups collaborate.
⚠️ On Linux, if you chmod the directory after setting ACLs, you may overwrite the mask, breaking the effective permissions of named groups. Always re-check with getfacl.
Verify exercises to earn ★ 150 XP and unlock next lab level.