Understanding Linux Permission Math
In POSIX systems (Linux, macOS, BSD), file access controls are computed using bitmasks where Read = 4, Write = 2, and Execute = 1.
Frequently Asked Questions
How do Linux file permissions work (Read, Write, Execute)?
Linux permissions are divided into three user classes: Owner (u), Group (g), and Others/Public (o). Each class has three permissions: Read (r = 4), Write (w = 2), and Execute (x = 1). The sum of these values creates the 3-digit octal permission number (e.g. 755 = rwxr-xr-x).
What is chmod 755 vs chmod 644?
chmod 755 gives the owner full permissions (read/write/execute) and gives group/others read and execute access (common for web directories and executable scripts). chmod 644 gives the owner read/write and gives group/others read-only access (standard for static files, HTML, and images).
What permissions should I use for SSH private keys?
SSH private keys (e.g., id_rsa, id_ed25519) require chmod 600 (owner read/write only) or chmod 400 (owner read-only). If permissions are too open, SSH clients will refuse to connect.
What are SUID, SGID, and the Sticky Bit?
SUID (4000) runs a binary with the file owner's privileges. SGID (2000) inherits group ownership for new files created in a directory. The Sticky Bit (1000, e.g. /tmp with chmod 1777) prevents users from deleting files owned by others.
How do I apply permissions recursively to an entire directory?
Use the '-R' flag in bash: 'chmod -R 755 /var/www/html' applies permissions recursively to all subdirectories and files.
Why should I avoid using chmod 777?
chmod 777 grants every user on the system full read, write, and execute permissions, creating a severe security vulnerability. Only use 777 for temporary local testing.