Linux File Permissions, ACLs & Special Bits: Complete Sysadmin Reference

Last Verified On: Kernel 6.8 / 6.12 LTS / Ubuntu 24.04 LTS & Debian 12/13 Moderate (Service Restart) Exit Code: 1

Direct Answer / TL;DR

Permission denied means the kernel's DAC check failed: mode bits and the POSIX ACL mask cap effective rights even when a named ACL entry grants rwx. Diagnose with namei -l and getfacl, then fix with chmod (octal 4/2/1 special-bit prefix), setfacl -m u:USER:rwx / m::, or SGID on shared dirs. Behavior identical on Ubuntu 24.04, Debian 12, and RHEL 9.

getfacl -p /path/to/target
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

Core Architecture & Mechanics

DAC evaluation order. On open(2) / execve(2), the kernel compares the calling process credentials (fsuid, egid plus supplementary groups, and capabilities CAP_DAC_OVERRIDE / CAP_DAC_READ_SEARCH) against the 12 permission bits stored in the inode i_mode field (visible via stat(2) as st_mode). Nine bits are the classic rwx triads; three are the special bits: S_ISUID (04000), S_ISGID (02000), S_ISVTX (01000). The owner triad wins if fsuid equals the inode uid; otherwise the group triad is consulted only if the process matches the inode gid (primary or supplementary); otherwise the other triad applies. Matching is first-match, no fall-through: being in the owning group and lacking r-x there does not fall through to a permissive other triad. On a directory, x (search) allows traversal into children, r only lists names. Root bypasses via CAP_DAC_OVERRIDE, which is why a daemon running as root never reports EACCES.

$ stat -c '%A (%a) %U:%G %n' /usr/bin/sudo /tmp
-rwsr-xr-x (4755) root:root /usr/bin/sudo
drwxrwxrwt (1777) root:root /tmp

Special bits on files. On an executable with an x bit set, S_ISUID makes execve(2) set the new process fsuid to the file’s owner; S_ISGID sets the egid to the file’s group. The kernel honors this only for real executables: the binfmt_script path drops the bits of the interpreted file and runs the interpreter with its own credentials, so SUID shell or Python scripts are inert. nosuid on the mount disables the bits silently for the whole filesystem — the common cause of “SUID mysteriously not working” on hardened /home or /tmp. Linux ignores SUID on directories entirely. SGID on directories has BSD semantics: new children inherit the directory’s group and the bit propagates to subdirectories; on ext4/tmpfs-basis filesystems the kernel strips the SGID bit from a new file when the creator is not a member of the inherited group. The kernel also strips SUID/SGID when a non-owner (lacking CAP_FOWNER) opens the file for writing — a frequent cause of bits vanishing after an editor or rsync run.

# Octal layout: [special][owner][group][other]
# 4xxx = SUID    2xxx = SGID    1xxx = Sticky

4755  rwsr-xr-x   SUID root binary     (sudo, passwd, pkexec)
2755  rwxr-sr-x   SGID binary          (write(1), wall(1): egid=tty)
1777  rwxrwxrwt   sticky world dir     (/tmp, /var/tmp)
2770  rwxrws---   shared team dir      (SGID + no access for other)
0644  rw-r--r--   default file         (umask 022 applied to 0666)
0755  rwxr-xr-x   default directory

ls letter state machine. Lowercase s / t in ls -l means special bit and the matching execute bit present (bit functional). Uppercase S or T means the special bit is set while the execute bit is clear (e.g. -rwSrwSr-- from a chmod 4644 typo): the bit is inert and a reliable misconfiguration tell.

umask. umask is a per-process attribute, inherited across fork(2)/execve(2); the kernel computes new_mode & ~umask at O_CREAT. umask never touches the special bits. The baseline UMASK 022 comes from /etc/login.defs; private-group schemes (pam_umask usergroups) drop it to 002 for regular users on Ubuntu and RHEL-style systems while root keeps 022. Verify live — do not assume:

$ umask
0002                       # typical user session, private-group scheme
$ umask 027 && touch /tmp/t && stat -c '%a' /tmp/t
640                        # 0666 & ~027

POSIX ACLs. Linux implements the withdrawn POSIX 1003.1e draft 17 ACLs as two xattrs: system.posix_acl_access (file ACL) and system.posix_acl_default (inheritable ACL on directories). When an access ACL exists, the VFS generic_permission() path delegates to posix_acl_permission(). Entry classes, evaluated strictly in this order with first-match-wins:

$ getfacl -p /srv/shared/report.csv
# file: /srv/shared/report.csv
# owner: alice
# group: devs
user::rw-            # 1. inode owner
user:bob:rw-         # 2. named users
user:ci:r--          #    (first match wins, no fall-through)
group::r--           # 3a. owning group
group:interns:r--    # 3b. named groups (first matching group wins)
mask::rw-            # caps class 3b + owning group + named users
other::r--           # 4. everyone else (never masked)

The mask entry caps the effective rights of named users, named groups and the owning group; getfacl prints the clipped result as #effective:r--. Every chmod call recalculates the mask from the group triad — named entries survive chmod but their effective rights collapse, which is the classic “ACL granted but still denied” state. ls -l appends + when an access ACL exists and . when only a SELinux context is present.

Default ACLs. On directories, a default ACL replaces umask math for newly created children: the resulting mode is the requested mode intersected with the default ACL entries, and a new subdirectory also inherits the default ACL itself. Provision a team tree with SGID plus a default ACL and umask differences between users become irrelevant.

Filesystem support. ACLs are compiled into ext4, XFS, Btrfs, tmpfs and overlayfs (CONFIG_*_FS_POSIX_ACL=y) and active by default; the historic acl mount flag is obsolete. vfat/exFAT, iso9660, squashfs and some NFS servers have no POSIX ACL support — setfacl then fails with Operation not supported. On NFSv4, getfacl shows a lossy POSIX view; audit the real ACL with nfs4_getfacl (package nfs4-acl-tools).

Complete Reference Table / Diagnostic Matrix

Item / Code / FlagBehaviorCommon Cause / Use Case
04000 (S_ISUID) on fileexecve sets fsuid to file owner; needs owner x; ignored on scripts, dirs, nosuid mountssudo, passwd, pkexec; broken state → “must be owned by uid 0”
02000 (S_ISGID) on fileexecve sets egid to file groupwall(1)/write(1) (setgid tty); Debian crontab (setgid crontab)
02000 on directoryNew children inherit dir group; kernel strips the file bit if creator not in groupShared team trees (/srv, web roots)
01000 (S_ISVTX) on directoryUnlink/rename only by file owner, dir owner, or CAP_FOWNER/tmp, /var/tmp at 1777
Uppercase S/T in ls -lSpecial bit set without matching x — inertchmod 4644-style typos; re-apply 4755
+ suffix in ls -lExtended access ACL present; displayed mode is the mask viewInspect with getfacl -p
mask:: (m::)Caps named users, named groups, owning groupRewritten by every chmod; reapply setfacl -m m::rw
default:: (d:) on dirInherited by new children; overrides umask for themsetfacl -d -m g:team:rwX /srv/shared
umask 0022 / 0002mode & ~umask at O_CREAT; special bits untouchedUMASK in /etc/login.defs, pam_umask usergroups
EACCES (13) “Permission denied”Mode/mask denial or missing traversal x in some parentnamei -l /path/to/file to walk the tree
EPERM (1) “Operation not permitted”Sticky-dir unlink by non-owner; chown of foreign fileIntended behavior of 1777 drop dirs
CAP_DAC_OVERRIDE / CAP_FOWNERBypass R/W/X checks; act as arbitrary ownerWhy root services never see EACCES
nosuid mount flagSUID/SGID silently ignored on the whole filesystemHardened /tmp, /home mounts; findmnt -no OPTIONS
fs.protected_regular=2O_CREAT on an existing file in a world-writable sticky dir requires ownershipDaemon writes into /tmp fail with EACCES after distro hardening

Multi-Distro Implementation Differences

Userland is identical across distros (coreutils + acl tools); differences are packaging, verification tooling and shipped defaults.

Ubuntu / Debian

# ACL tools not guaranteed in minimal images
dpkg -s acl >/dev/null 2>&1 || apt-get install -y acl
umask                                                    # root 0022, users 0002 (private-group)
stat -c '%A %a %U %G %n' /usr/bin/passwd /usr/bin/sudo   # rwsr-xr-x 4755
stat -c '%A %G %n' /usr/bin/crontab /var/spool/cron/crontabs
# rwxr-sr-x crontab ... drwx-wx--T crontabs (SGID + sticky spool)
# Note: dpkg -V verifies checksums, NOT file modes -
# compare against a reference container or reinstall to restore

RHEL / AlmaLinux / Rocky

dnf -y install acl
rpm -V sudo passwd                 # M in col 2 = package mode drift
ls -l /usr/bin/sudo /usr/bin/wall  # 4755 root, rwxr-sr-x root:tty
# SELinux MAC still applies after any chmod/ACL fix:
ls -Z /var/www
ausearch -m AVC -ts recent | tail -n 20

Arch Linux

pacman -S --needed acl
# pacman verifies modes with -kk (Permission mismatch = drift):
pacman -Qkk 2>/dev/null | grep -i 'permission mismatch' | head
find /usr -xdev -type f ( -perm -4000 -o -perm -2000 ) -ls
# expected set is tiny: sudo, passwd, pkexec, fusermount...

Alpine / Containers

apk add acl                        # getfacl/setfacl absent in base images
find / -type f -perm -4000 2>/dev/null   # busybox find, decimal syntax
stat -c '%A %U %G' /bin/busybox
# Containers usually run as root, so special bits are irrelevant
# until you USER/step down; prefer dropping caps:
# setfacl works on overlay2 backed by ext4/xfs upperdir

Common Failure Modes & Troubleshooting Recipes

Each recipe below is reproducible verbatim; commands run as shown are read-only unless marked.

Recipe 1 — ACL granted but still denied: the mask. Symptom: setfacl -m u:ci:rw done, user still gets Permission denied. Cause: the mask entry caps the grant (typically after a previous chmod).

$ getfacl -p /srv/app | grep -E 'mask|ci'
user:ci:rw-        #effective:r--
mask::r--
$ setfacl -m m::rw /srv/app           # reopen the mask
$ getfacl -p /srv/app | grep ci       # #effective now rw-

Recipe 2 — Broken SUID on sudo (exact production error). Triggered by a careless chown -R or a bad rsync of /usr. Restore from a root rescue shell (or su from another admin account):

stat -c '%A %U:%G %n' /usr/bin/sudo   # expect -rwsr-xr-x root root
chown root:root /usr/bin/sudo
chmod 4755 /usr/bin/sudo
sudo -V | head -n1                    # sanity check

On RHEL/Alma and Arch, prefer reinstalling the package over hand-fixing: dnf reinstall sudo / pacman -S sudo; on Debian/Ubuntu, apt-get install --reinstall sudo.

Recipe 3 — SUID/SGID silently not honored. Three checks, in order: the filesystem mount (nosuid disables bits with no error), the file type (scripts are exempt), and whether something stripped the bits (non-owner write, chown without CAP_FOWNER):

findmnt -no TARGET,OPTIONS /home /tmp     # look for nosuid,noexec
file /path/to/launcher                    # "script" = bits ignored by kernel
stat -c '%A' /path/to/launcher            # S/T uppercase = missing x bit

Recipe 4 — Sticky-bit EPERM in shared directories. rm: cannot remove 'x': Operation not permitted inside a 1777 dir is by design: only the file owner, dir owner or root may unlink. For a team tree, replace the anonymous drop-box model with SGID + default ACLs:

getfacl -R -p /srv/app > /root/acl.before          # rollback snapshot
find /srv/app -printf '%m %pn' > /root/modes.before
# DRY-RUN: list what would change before touching anything
find /srv/app -type d -perm /0002 -o -type f -perm /0022 -print
groupadd -f ops
chgrp -R ops /srv/app
find /srv/app -type d -exec chmod 2770 {} +
find /srv/app -type f ( -perm /111 ! -perm /111 ) -print  # sanity: execs kept
setfacl -R -m g:ops:rwX /srv/app
setfacl -R -d -m g:ops:rwX /srv/app
getfacl -p /srv/app | tail -n 6                    # verify default block

Rollback: setfacl --restore=/root/acl.before; re-apply baseline modes from the snapshot only after diffing it against the live tree. This is the safe replacement for a blind chmod -R, which destroys the distinction between files and directories and is not self-rollback.

Recipe 5 — EACCES deep in the tree, not at the file. The denial is usually a missing x (traverse) on an intermediate directory. namei -l prints every component with its mode:

$ namei -l /var/www/app/storage/cache
drwxr-xr-x root     root     /
drwxr-xr-x root     root     var
drwxr-xr-x root     root     www
drwxr-x--- www-data www-data app      # o=x missing here -> EACCES
$ chmod o+x /var/www/app              # traverse only, no listing (never o+rx blind)

Recipe 6 — setfacl: Operation not supported. The target filesystem has no POSIX ACL xattr support (vfat, exFAT, squashfs, some NFS servers). Identify it and fall back to plain mode bits or move the data:

setfacl -m u:jenkins:rx /mnt/usb/data 2>&1
findmnt -T /mnt/usb/data        # FSTYPE vfat/exfat -> no ACL layer

Recipe 7 — Daemon fails writing /tmp after distro update. Modern kernels with fs.protected_regular=2 (Ubuntu 24.04 ships this) refuse O_CREAT on a file in a world-writable sticky directory unless the opener owns the file; symptom is EACCES in mkstemp()-style code that two different uids use. Fix the code to use a dedicated group-writable directory, not the sysctl:

sysctl fs.protected_regular
ls -ld /tmp                     # drwxrwxrwt confirms the sticky model

Production Hardening & Safety Checklist

Safety Check: Before any recursive or bulk permission change: (1) snapshot state — getfacl -R -p /target > /root/acl.before and find /target -printf '%m %pn' > /root/modes.before; (2) dry-run with find ... -print before any -exec chmod; (3) validate as the actual service identity — runuser -u appuser -- test -r /srv/file or setpriv --reuid=appuser --regid=appuser --clear-groups test -w /srv/file; (4) keep the rollback command (setfacl --restore) executable-in-one-line before proceeding; (5) never use chmod 777 — it masks the real ACL/SUID defect and widens attack surface.

  • Audit SUID/SGID inventory on every host and keep the expected list small: find / -xdev -type f ( -perm -4000 -o -perm -2000 ) -ls 2>/dev/null. Detect drift with rpm -V (RHEL/Alma), pacman -Qkk (Arch); on Debian/Ubuntu dpkg -V does not check modes, so verify with stat against a fresh reference image and reinstall packaged binaries instead of hand-repairing when in doubt.
  • Neutralize special-bit abuse with mount flags: mount /tmp, /var/tmp, /dev/shm, /home and /var with nosuid,nodev,noexec where data (not executables) belongs. This is defense in depth against planted SUID payloads; findmnt verifies the live flags.
  • Enforce kernel hardening sysctls: fs.protected_symlinks=1, fs.protected_hardlinks=1, fs.protected_regular=2, fs.protected_fifos=2 via /etc/sysctl.d/99-hardening.conf; expect EACCES fallout in legacy code that uses 1777 directories as a store, and fix the storage layout, not the sysctl.
  • Permission model: baseline modes 0640/0660 with groups + default ACLs; sticky 1777 reserved for genuine public drop zones; SGID directories for all shared writable trees; uppercase S/T from ls -l is a defect to fix, not noise.
  • umask policy: tighten via UMASK 027 in /etc/login.defs plus pam_umask; verify a real session with su - appuser -c umask rather than trusting config.
  • Remember the second gate: on RHEL/Alma, SELinux MAC applies after DAC — a 0777 file can still be denied; diagnose with aub tools (ausearch -m AVC, ls -Z). ACLs and special bits never override MAC.

Frequently Asked Edge Cases

Does SUID work on shell or Python scripts?

No. The kernel's binfmt_script path discards S_ISUID/S_ISGID of the interpreted file and runs the interpreter with its own credentials, so a SUID script is inert. Use a sudoers rule (sudo -u), a compiled helper, or file capabilities (setcap) instead.

Why do setfacl rights stop working right after a chmod?

chmod rewrites the group triad and with it the ACL mask, so named entries remain but their effective rights collapse (shown as #effective in getfacl). Restore with setfacl -m m::rw or align the chmod with the intended mask.

setfacl prints 'Operation not supported' - is the mount broken?

No. The filesystem lacks POSIX ACL xattr support (vfat, exFAT, squashfs, iso9660, some NFS servers). Confirm with findmnt -T /path, then either use plain chown/chmod or relocate the data to ext4/XFS/Btrfs.

References & Upstream Docs

  1. Linux man-pages: chmod(1), setfacl(1), getfacl(1), acl(5), umask(2), xattr(7), capabilities(7)
  2. man7.org Linux man-pages: acl(5) POSIX Access Control Lists overview
  3. kernel.org: Documentation/admin-guide/sysctl/fs.rst (fs.protected_regular, fs.protected_symlinks)
  4. POSIX 1003.1e Draft 17 (withdrawn ACL standard as implemented by the Linux VFS)

Related Concepts