All cheat sheets

chmod Cheat Sheet

Linux file permissions: symbolic and octal modes, common combos, and pitfalls.

CLI & Shell
chmod
permissions
linux

chmod changes permission bits on files and directories. Permissions are evaluated for the owner, group, and other users, with directory permissions controlling traversal and listing as well as file access.

Reading `ls -l`

A mode such as -rwxr-x--- begins with the file type, then has three permission triples: user, group, and other.

bash
ls -l script.sh
# -rwxr-x--- 1 ada developers 842 Jul 28 09:00 script.sh
Table
PositionExampleMeaning
First character-Regular file; d means directory; l means symlink.
Characters 2–4rwxOwner permissions.
Characters 5–7r-xGroup permissions.
Characters 8–10---Other-user permissions.
s / trws, tSpecial set-ID or sticky bits when present.

Permission triples

For regular files, read permits content inspection, write permits modification, and execute permits running the file. For directories, read lists entries, write changes entries, and execute permits traversal.

Table
SymbolNumeric valueMeaning
r4Read.
w2Write.
x1Execute or traverse.
-0Permission absent.
bash
# user=rwx, group=r-x, other=---
chmod 750 deploy.sh

Octal modes

Each octal digit is the sum of the three bits for one class. A leading fourth digit can represent special bits, such as setuid, setgid, or sticky.

Table
OctalBitsSymbolic
0---None
1--xExecute
2-w-Write
3-wxWrite + execute
4r--Read
5r-xRead + execute
6rw-Read + write
7rwxRead + write + execute
Table
ModeTypical use
755Executable files or traversable public directories.
644Ordinary readable files.
600Private user-readable files.
700Private executable directories or scripts.
640Owner read/write, group read, no other access.
bash
chmod 755 script.sh
chmod 644 config.example
chmod 600 ~/.ssh/config

Symbolic modes

Symbolic syntax identifies a class, an operator, and permissions. Omitting the class uses the process umask for many commands, so specify the class when precision matters.

bash
chmod u+x script.sh
chmod go-w shared.txt
chmod a=r public.txt
chmod u=rw,go=r report.txt
chmod u+rwx,g+rx,o-rwx private-dir
Table
FormMeaning
uUser/owner.
gGroup.
oOther.
aAll three classes.
+Add permissions.
-Remove permissions.
=Set exactly these permissions.

Recursive changes

-R applies changes below a directory. It is often safer to handle directories and files separately so directories receive execute permission while data files do not.

bash
find project -type d -exec chmod 755 {} +
find project -type f -exec chmod 644 {} +
chmod -R u+rwX,go+rX project

Pitfalls and special cases

Avoid 777 as a default: it allows any user to modify or execute content. A directory needs x for access, and changing a symlink usually affects its target because chmod follows the link on common systems.

bash
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 1777 /tmp/shared

References