CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Permissions & Ownership / getfacl

getfacl

Show a file's ACL

Intermediatepermissionsaclaudit

getfacl prints the full permission picture of a file: owner, group, special flags, the base entries, every named user and group entry, the mask and any default ACL, with #effective notes where the mask cuts rights. Its output can be saved and fed back to setfacl to restore permissions.

Syntaxgetfacl [-R] [-p] [-c] [-e] [-a | -d] [-t] FILE...

Watch it run

ls -l shows a + on /srv/app/logs and you want to see who else has access.

devops@devops-lab: /srv/app — zsh — 96×28
➜ /srv/app
Step 1 of 3
ls -ld logs

The + says there's more than the mode bits. Note the group triplet rwx here is the MASK, not group::.

Anatomy of a command

$
commandgetfacl

Reads and prints POSIX ACLs (package acl).

How it works

getfacl calls getxattr for system.posix_acl_access (and system.posix_acl_default on directories) through libacl. If a file has no extended ACL, it builds the three base entries from the ordinary mode bits, so it works on any file. It prints a header (# file, # owner, # group, and # flags when setuid, setgid or sticky are set, as a three-character s/s/t string), then the entries in canonical order: user::, user:NAME:, group::, group:NAME:, mask::, other::, followed by default: entries. For each named user and group entry it compares the permissions with the mask and appends #effective: when the mask removes bits. Names are resolved through NSS; with -n you get numeric IDs. By default it strips the leading / from paths and warns on stderr, so a dump made with -R is meant to be restored with cd / first.

Options you'll actually use

-RRecurse into directories
-pDon't strip the leading / (absolute paths)
-c / --omit-headerDon't print the # file/owner/group header
-ePrint #effective for every entry, even when unchanged
-a / -dOnly the access ACL / only the default ACL
-tTabular format (base entries in capitals)
-nNumeric UIDs and GIDs
-sSkip files that only have the base entries

Common mistakes

Judging access from ls -l alone on a file with a +

ls shows the mask in the group slot and nothing about named entries.

getfacl FILE (and read any #effective notes)
Restoring a getfacl -R dump from the wrong directory

Without -p the paths are stored relative (srv/app/...), so setfacl --restore can't find them.

cd / && setfacl --restore=FILE, or dump with getfacl -R -p
Reading the entry text (rw-) as the actual right

The mask can remove bits; the real right is the #effective value.

Use getfacl -e to print effective rights for every entry

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show the ACL of your home directory, then of /tmp. What does the # flags line for /tmp mean?

  2. 2

    Give www-data read on a file in ~/data, then print the ACL without the header.

  3. 3

    Save the ACLs of ~/data recursively with absolute paths, remove all ACLs, then restore them.

Related commands

setfaclGrant per-user and per-group access with ACLschmodChange file permissionslsList directory contentsstatShow a file's inode: size, permissions, owner and timestamps
PrevioussetfaclNextenv
Linux / Permissions & Ownership / getfacl

getfacl

Show a file's ACL

Intermediatepermissionsaclaudit

getfacl prints the full permission picture of a file: owner, group, special flags, the base entries, every named user and group entry, the mask and any default ACL, with #effective notes where the mask cuts rights. Its output can be saved and fed back to setfacl to restore permissions.

Syntaxgetfacl [-R] [-p] [-c] [-e] [-a | -d] [-t] FILE...

Watch it run

ls -l shows a + on /srv/app/logs and you want to see who else has access.

devops@devops-lab: /srv/app — zsh — 96×28
➜ /srv/app
Step 1 of 3
ls -ld logs

The + says there's more than the mode bits. Note the group triplet rwx here is the MASK, not group::.

Anatomy of a command

$
commandgetfacl

Reads and prints POSIX ACLs (package acl).

How it works

getfacl calls getxattr for system.posix_acl_access (and system.posix_acl_default on directories) through libacl. If a file has no extended ACL, it builds the three base entries from the ordinary mode bits, so it works on any file. It prints a header (# file, # owner, # group, and # flags when setuid, setgid or sticky are set, as a three-character s/s/t string), then the entries in canonical order: user::, user:NAME:, group::, group:NAME:, mask::, other::, followed by default: entries. For each named user and group entry it compares the permissions with the mask and appends #effective: when the mask removes bits. Names are resolved through NSS; with -n you get numeric IDs. By default it strips the leading / from paths and warns on stderr, so a dump made with -R is meant to be restored with cd / first.

Options you'll actually use

-RRecurse into directories
-pDon't strip the leading / (absolute paths)
-c / --omit-headerDon't print the # file/owner/group header
-ePrint #effective for every entry, even when unchanged
-a / -dOnly the access ACL / only the default ACL
-tTabular format (base entries in capitals)
-nNumeric UIDs and GIDs
-sSkip files that only have the base entries

Common mistakes

Judging access from ls -l alone on a file with a +

ls shows the mask in the group slot and nothing about named entries.

getfacl FILE (and read any #effective notes)
Restoring a getfacl -R dump from the wrong directory

Without -p the paths are stored relative (srv/app/...), so setfacl --restore can't find them.

cd / && setfacl --restore=FILE, or dump with getfacl -R -p
Reading the entry text (rw-) as the actual right

The mask can remove bits; the real right is the #effective value.

Use getfacl -e to print effective rights for every entry

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show the ACL of your home directory, then of /tmp. What does the # flags line for /tmp mean?

  2. 2

    Give www-data read on a file in ~/data, then print the ACL without the header.

  3. 3

    Save the ACLs of ~/data recursively with absolute paths, remove all ACLs, then restore them.

Related commands

setfaclGrant per-user and per-group access with ACLschmodChange file permissionslsList directory contentsstatShow a file's inode: size, permissions, owner and timestamps
PrevioussetfaclNextenv