Linux Permissions, Special Bits & umask Reference
Unix and Linux permissions map three permission bits—Read (4), Write (2), and Execute (1)—across Owner (u), Group (g), and Other (o), plus an optional leading octal digit for special execution and directory semantics.
- Secrets & SSH Keys (
0600): OpenSSH refuses private keys readable by group or other. Always setchmod 600 ~/.ssh/id_ed25519andchmod 600 .envfor API tokens or webhooks. - SGID on Shared Directories (
2775): Setting SGID on a directory forces newly created files inside it to inherit the directory's group ownership rather than the creator's primary group. - Sticky Bit (
1777): Used on world-writable directories like/tmpso users can only delete or rename files they own. - How
umaskWorks: The kernel masks out bits from the base creation mode (0666for files,0777for directories) via bitwise AND-NOT:effective = base & ~umask. Hardened servers often useumask 0027so files default to0640(no world read).
Frequently Asked Questions
Why is chmod 777 dangerous on web or application servers?
0777 grants every local user and compromised service account full read, write, and execute rights. On shared hosts or container volumes, an attacker can overwrite scripts or inject payloads executed by privileged processes.
What is the difference between lowercase s and uppercase S in ls -l?
Lowercase s (e.g. rwsr-xr-x) means SUID/SGID is set AND the underlying execute bit is enabled. Uppercase S (rwSr-xr-x) means SUID/SGID is set WITHOUT the execute bit.