Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Permissions and Users

Linux getfacl and setfacl commands

Reference for getfacl and setfacl: give extra users or groups access to files beyond owner/group/other, set default ACLs on directories and read the mask.

Classic Unix permissions allow exactly one owner, one group and "everyone else". An access control list (ACL) lifts that limit: you can grant a specific extra user or group read or write access to a file without changing its owner or group. setfacl modifies ACLs and getfacl displays them; both come from the acl package and need a file system mounted with ACL support (the default for ext4, XFS and Btrfs on current distributions).

A file that has an ACL shows a + after the permission string in ls -l, for example -rw-rw-r--+. ACLs are most useful on shared directories, where you want a default that applies to every file created there later.

Terminal
setfacl -m u:alice:rw file
getfacl file

Try it

The ACL tools are not installed in the sandbox, so both examples are read-only: the first shows realistic output, the second parses it with ordinary text tools.

Bash What getfacl prints (read-only sample)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Parsing an ACL listing (sample data)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
getfacl [-R] [-d] [-n] FILE...
setfacl [-R] [-d] [-n] {-m ACL | -x ACL | -b | -k} FILE...
setfacl --set-file=- FILE...

An ACL entry has the form TYPE:NAME:PERMS, where TYPE is u (user), g (group), o (other) or m (mask). An empty NAME means the owner, the owning group, or "other".

Option Description
-m ACL Modify: add or change entries, for example u:alice:rw,g:audit:r.
-x ACL Remove the named entries (no permissions needed after the name).
-b Remove all extended entries, leaving only the basic permissions.
-k Remove the default ACL of a directory.
-d Operate on the default ACL (inherited by new files and subdirectories).
-R Recurse into directories.
-n Do not recalculate the mask.
-M FILE, -X FILE Read entries to modify / remove from a file.
--set-file=FILE Replace the whole ACL from a file (- for stdin; getfacl a | setfacl --set-file=- b copies an ACL).

Returns: 0 on success; 1 on error (for example the file system does not support ACLs: Operation not supported).

Usage notes

  • The mask is a ceiling. The mask:: entry limits the effective rights of all named users, named groups and the owning group. If it says r--, a named user entry of rw- shows #effective:r-- in getfacl output. setfacl -m recalculates it; chmod's group bits change it too.
  • chmod and ACLs interact. On a file with an ACL, chmod g+w modifies the mask, not only the group entry. Surprising results usually come from this.
  • Default ACLs (setfacl -d -m g:team:rwx dir) apply to new files and directories created in dir; they do not change existing files. Combine with -R and a normal -m call to fix existing content.
  • Copying files with cp -p/cp -a, rsync -A and tar --acls keeps ACLs; plain cp and mv across file systems may lose them.
  • Backup and restore: getfacl -R . > acls.txt then setfacl --restore=acls.txt.
  • Not every file system supports ACLs (FAT, some network mounts). Check the mount options with mount.
  • Prefer groups when they are enough. ACLs add a second place where access is decided; document them. See ACLs and attributes.