What chmod does¶
chmod stands for change mode. It modifies the read, write, and execute permissions on a file or directory for three groups: the owning user (u), the owning group (g), and everyone else (o).
Linux represents permissions as a 9-bit string — three bits per group:
-rwxr-xr--
^^^ owner: rwx (read + write + execute)
^^^ group: r-x (read + execute)
^^^ others: r-- (read only)
Symbolic mode¶
The symbolic form uses letters and operators:
# Add execute permission for the owner
chmod u+x script.sh
# Remove write permission from group
chmod g-w report.txt
# Set exact permissions (= replaces, does not add)
chmod u=rw,g=r,o= private.conf
# Apply to everyone
chmod a+r public.html
Operators: + adds, - removes, = sets exactly.
Octal mode¶
The octal form uses three digits, one per group. Each digit is the sum of: 4 (read) + 2 (write) + 1 (execute).
| Octal | Binary | Meaning |
|---|---|---|
| 7 | 111 | rwx |
| 6 | 110 | rw- |
| 5 | 101 | r-x |
| 4 | 100 | r-- |
| 0 | 000 | --- |
# Common patterns
chmod 755 script.sh # rwxr-xr-x — executable, others can read/execute
chmod 644 config.txt # rw-r--r-- — owner edits, others read
chmod 600 id_rsa # rw------- — SSH private key, no group/other access
chmod 700 ~/.ssh # rwx------ — SSH directory, owner only
chmod 777 /tmp/shared # rwxrwxrwx — everyone full access (use with care)
Recursive chmod¶
# Apply recursively to a directory tree
chmod -R 755 /var/www/html
# Fix a common mistake: executable bit set on all files
find /var/www/html -type f -exec chmod 644 {} \;
find /var/www/html -type d -exec chmod 755 {} \;
Tip: Use
findwith-type fand-type dto apply different permissions to files and directories — recursivechmod -Rapplies the same mode to both.
Special permission bits¶
Beyond the standard 9 bits, three special bits exist:
| Bit | Octal | Effect |
|---|---|---|
| setuid | 4000 | Executable runs as file owner |
| setgid | 2000 | New files inherit group / executable runs as group |
| sticky | 1000 | Only owner can delete files (common on /tmp) |
chmod u+s /usr/bin/sudo # setuid — 4755
chmod g+s /shared # setgid on directory — 2755
chmod +t /tmp # sticky bit — 1777
Check current permissions¶
ls -l file.txt
# -rw-r--r-- 1 alice devs 1234 May 28 2026 file.txt
stat file.txt
# Access: (0644/-rw-r--r--)
Key takeaways¶
- Symbolic mode (
u+x) is easier to read; octal mode (755) is faster to type. 644for files,755for directories is the safe default for web content.600for private keys and sensitive config — no group, no others.- Prefer
findover-Rwhen files and directories need different modes.