Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

ACLs vs chmod: Linux File Permissions Guide

· 5 min read · Home Tech

In this article
  1. What Are Access Control Lists (ACLs)?
  2. How ACLs Work: The Basics
  3. Using setfacl and getfacl
  4. When to Use ACLs Instead of chmod
  5. Common Pitfalls and Misconceptions
  6. Comparing ACLs to chmod and Groups
  7. Performance and Compatibility Considerations
  8. Frequently Asked Questions

Yes, you can use Access Control Lists (ACLs) to control file permissions in Linux, and they extend the traditional chmod model by letting you grant permissions to multiple specific users and groups on a single file or directory. While chmod only allows one owner, one group, and a set of "others" permissions, ACLs let you define fine-grained rules such as "give user Alice read and write, give group devs read-only, and deny user Bob all access."

What Are Access Control Lists (ACLs)?

An ACL is a list of entries attached to a file or directory. Each entry specifies a user, a group, or a default rule, along with the permissions (read, write, execute) granted or denied. Linux supports POSIX ACLs, which are implemented by the acl package and the ext4, XFS, and Btrfs filesystems (among others). The traditional Unix permission model is actually a simplified view of an ACL: when you run ls -l, you see the first three entries (owner, group, others), but there can be many more hidden entries.

How ACLs Work: The Basics

ACLs add two types of entries beyond the standard three:

  • Named user entries (e.g., user:alice:rw-) grant or deny permissions to a specific user.
  • Named group entries (e.g., group:devs:r--) grant or deny permissions to a specific group.

There is also a mask entry that limits the effective permissions of named users, named groups, and the owning group. The mask acts as a ceiling: a named user cannot have more permissions than the mask allows, even if their entry says otherwise. For example, if the mask is r--, a named user entry rw- will actually be effective as r--.

Using setfacl and getfacl

The two main commands are setfacl (set ACL) and getfacl (get ACL). Here is how you use them:

  1. View an ACL: getfacl filename – this shows all entries, including the traditional owner/group/others as user::, group::, and other::.
  2. Add a named user entry: setfacl -m u:alice:rw filename – grants Alice read and write.
  3. Add a named group entry: setfacl -m g:devs:r filename – grants the group devs read.
  4. Remove an entry: setfacl -x u:alice filename – removes Alice's entry.
  5. Set a default ACL on a directory: setfacl -d -m u:alice:rw dirname – new files inside will inherit this rule.

When you set an ACL, the traditional permission bits are updated to reflect the mask. Running ls -l will show a + sign at the end of the permission string (e.g., -rw-rw----+) to indicate that an ACL is present.

When to Use ACLs Instead of chmod

ACLs are useful when you need to share files among multiple users or groups with different levels of access. Common scenarios include:

  • A project directory where several users need write access but others should only read.
  • A web server directory where the web user needs read, a developer group needs write, and a backup user needs read.
  • A shared folder where new files should automatically be accessible to a specific group (using default ACLs).

If your situation only involves one owner, one group, and everyone else, chmod is simpler and sufficient. ACLs add complexity, so use them only when the traditional model does not fit.

Common Pitfalls and Misconceptions

One common mistake is forgetting that the mask can silently limit permissions. If you set a named user to rwx but the mask is r-x, the user will not actually get write access. Always check getfacl to see the effective permissions.

Another issue is that ACLs do not replace the owner and group fields. The owner entry (user::) and group entry (group::) still exist and cannot be removed. Also, when you copy or backup files, ACLs may not be preserved unless you use tools that support them (e.g., cp -p or tar --acls).

Some users think ACLs are a security boundary, but they are just permission rules. If a user can change the ACL (i.e., they own the file), they can grant themselves any permission. ACLs do not bypass the usual ownership rules.

Comparing ACLs to chmod and Groups

The traditional Unix model has three categories: owner, group, others. This works fine for simple cases, but it becomes limiting when you need to give different permissions to two different groups. You could create a new group that contains both groups, but that is cumbersome and does not allow per-user exceptions. ACLs solve this by allowing arbitrary user and group entries.

Another alternative is using chown to change the owner or group, but that changes ownership for everyone. ACLs let you grant or revoke specific permissions without altering the file's owner or primary group.

Performance and Compatibility Considerations

ACLs are stored as extended attributes on the filesystem, so they add a small overhead to file operations. In practice, this is negligible for most workloads. However, not all filesystems support ACLs. If you are using a filesystem like FAT32 or older versions of some network filesystems, ACLs may not work.

When moving files between systems, ACLs can be lost if the destination filesystem does not support them or if the tools used do not preserve them. Always verify with getfacl after copying if ACLs are critical.

Frequently Asked Questions

How do I set an ACL that applies to all future files in a directory?

Use a default ACL on the directory: setfacl -d -m u:alice:rw /path/to/dir. New files and subdirectories created inside will inherit this ACL. Note that the default ACL is only applied at creation time; existing files are not affected.

Can ACLs override the traditional chmod permissions?

Yes and no. The ACL entries for the owner, group, and others are exactly the same as the traditional bits. Named user and group entries add extra rules. The mask limits the effective permissions of named entries and the owning group, but the owner entry is not affected by the mask.

How do I remove all ACLs from a file?

Run setfacl -b filename to remove all extended ACL entries, leaving only the traditional owner/group/others. The + sign in ls -l will disappear.

Do ACLs work on all Linux filesystems?

Most modern filesystems like ext4, XFS, Btrfs, and ZFS support POSIX ACLs. You may need to mount the filesystem with the acl option (though it is often enabled by default). Some filesystems like FAT and exFAT do not support them.

What is the difference between a mask and a group entry?

The mask is a special entry that limits the maximum permissions for named users, named groups, and the owning group. It is not a specific user or group itself. The group entry (e.g., group:devs:r--) grants permissions to a particular group, but those permissions are subject to the mask.