How to Calculate Unix File Permissions (chmod)
Octal and symbolic chmod notation, the special bits, and what read, write and execute actually do on a directory, measured as an ordinary Linux user (744 lists names but blocks every file; 777 lets anyone delete your files).
Permission Basics
Every file and directory has an owner, a group and three permission sets: for the owner, for members of the group, and for everyone else. Each set has read (r), write (w) and execute (x). rwxr-xr-- means the owner can do everything, the group can read and execute, and others can only read.
Numeric (Octal) Notation
Read = 4, write = 2, execute = 1; add them per set. rwx = 7, r-x = 5, r-- = 4, so rwxr-xr-- is 754. A fourth leading digit holds the special bits: setuid (4), setgid (2) and sticky (1), so chmod 1777 is rwx for everyone plus sticky, shown by ls -l as drwxrwxrwt.
What r, w and x Mean on a Directory: Measured
On files the letters mean what they say. On directories they do not, and that is where most permission bugs live. We created a directory owned by root containing a world-readable file and tried to use it as an ordinary user (Linux, GNU coreutils; root ignores these checks, so the test needs a normal account):
| Directory mode | ls (list names) | cat a file inside | ls -l (details) |
|---|---|---|---|
| 755 | works | works | works |
| 744 (r without x) | works | denied | denied |
| 711 (x without r) | denied | works if you know the name | denied |
| 700 | denied | denied | denied |
- r on a directory lets you list the names in it.
- x lets you pass through it to reach what is inside, including reading a file whose name you already know. Without x, read permission on the file itself does not help.
- w (with x) lets you create, rename and delete entries. In our test an ordinary user deleted a read-only file owned by root from a 777 directory. Setting the sticky bit (1777, as on
/tmp) stopped that: users can then delete only their own files.
Where 644 and 755 Come From: umask
New files start at 666 and directories at 777, minus the bits in your umask. With the common umask 022 you get 644 files and 755 directories; Debian and Ubuntu give users their own group and a umask of 002, which is what our test account had, producing 664 and 775. Check yours with umask.
Common Settings
| Mode | Use |
|---|---|
| 644 | Ordinary files a web server only reads (HTML, CSS, images) |
| 755 | Directories, and scripts that must run |
| 600 | Private keys, files holding passwords; SSH refuses private keys readable by others |
| 700 | Directories only you should enter, such as ~/.ssh |
| 1777 | Shared scratch directories like /tmp |
| 777 | Almost never: any user or compromised process can change or replace the file, and on a directory can delete others' files |
The Chmod Calculator converts between checkboxes, octal (including the special-bit digit) and the ls -l string, and writes a symbolic command such as chmod u=rwx,g=rx,o=rx that chmod accepts; we checked its output against GNU chmod for 307 modes.