How chmod numbers work
Each digit is the sum of read (4), write (2) and execute (1), for the owner, the group and everyone else, in that order. So 7 = 4+2+1 (read, write, run), 5 = 4+1 (read, run) and 4 = read only.
| Number | Symbolic | Typical use |
|---|---|---|
| 755 | rwxr-xr-x | Folders, scripts, programs |
| 644 | rw-r--r-- | Web pages, images, config files |
| 600 | rw------- | SSH private keys, .env files |
| 700 | rwx------ | Private folders like ~/.ssh |
| 777 | rwxrwxrwx | Avoid: anyone can change the file |
Special permissions
A fourth leading digit sets setuid (4), setgid (2) and the sticky bit (1). The sticky bit on a shared folder like /tmp (1777) stops users deleting each other's files. They show as s or t in the symbolic form.
Questions people ask
What does chmod 755 mean?
The owner can read, write and execute; the group and everyone else can read and execute. It's the usual setting for folders and scripts.
Should I ever use chmod 777?
Almost never. It lets any user or compromised process change the file. Fix the file's owner with chown instead.
What's the -R option?
It applies the permissions to a folder and everything inside it. Be careful: files usually want 644 and folders 755, so use find with -type f and -type d for mixed trees.