Mastering Octal Modes, Special Bits, and Safe Recursive chmod Commands
POSIX file permissions pack 12 bits into four octal digits: the leading special triad (SUID=4, SGID=2, Sticky=1) followed by Owner (u), Group (g), and Others (o). On directories, the execute bit (x) controls traversal rather than program execution—which is why web roots use 0755 on directories and 0644 on static files.
Never run 'chmod -R 644 /var/www' (which strips directory traversal bits and locks out Nginx) or 'chmod -R 755 /var/www' (which makes every uploaded HTML/image file executable). Instead, split directories and files cleanly with 'find /var/www -type d -exec chmod 755 {} +' and 'find /var/www -type f -exec chmod 644 {} +'.
- Permission Bit WeightsRead (r) = 4 (100), Write (w) = 2 (010), Execute/Traverse (x) = 1 (001) across Owner, Group, and Others.
- Special Mode Bits4000 = SetUID (s/S), 2000 = SetGID (s/S), 1000 = Sticky Bit (t/T) for shared /tmp directories.
- Security Audit RulesFlags world-writable (xx2/xx6/xx7) hazards, OpenSSH key rejection (>0600), and SUID root escalation risks.
Why does SSH reject private keys with chmod 644?
OpenSSH refuses any private key readable by Group or Others (throwing 'UNPROTECTED PRIVATE KEY FILE'). Set keys to chmod 600 (rw-------) or chmod 400 (r--------) for AWS .pem files.
What is the difference between lowercase 's'/'t' and uppercase 'S'/'T' in ls -l?
Lowercase s or t means the underlying execute (x) bit is also set (e.g., 4755 → rwsr-xr-x). Uppercase S or T warns that the special bit is set WITHOUT execute permission (e.g., 4644 → rwSr--r--).
Why should chmod 777 never be used in production?
chmod 777 grants read, write, and execute permissions to every local user and compromised service account on the host. Fix ownership with chown or group permissions (0775 / 2775) instead.