SUID, SGID, Sticky & umask
Special Permission Bits
| Bit | Octal | On a file | On a directory |
|---|---|---|---|
| SUID | 4000 | Runs as file owner (e.g. passwd) | - |
| SGID | 2000 | Runs as file group | New files inherit the dir's group |
| Sticky | 1000 | - | Only the owner can delete their files (e.g. /tmp) |
$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 59976 /usr/bin/passwd # s = SUID
$ ls -ld /tmp
drwxrwxrwt 10 root root 4096 /tmp # t = sticky
Set them: chmod 4755 file (SUID), chmod 2775 dir (SGID), chmod +t dir (sticky).
umask
umask subtracts permissions from the defaults (666 files, 777 dirs) for newly created files.
umask 022 → files 644, dirs 755 (typical default)
umask 077 → files 600, dirs 700 (private)
Exam tip: ACLs (getfacl/setfacl) grant permissions beyond the basic three classes, e.g.setfacl -m u:bob:rw file. A+at the end ofls -lpermissions means an ACL is present.