Chmod calculator and how octal permissions work
Every file on Linux and macOS carries nine permission bits. The chmod number, such as 755 or 644, is those bits written as three octal digits. Tick the boxes below, or learn the small sum that turns them into a number.
Permission calculator
Three groups, three bits each
Unix asks three questions about every file. Who owns it (the user)? Which group does it belong to? And what about everybody else? For each of those three classes there are three switches: read, write and execute. That gives nine bits in total, and ls -l prints them as a ten-character string such as -rwxr-xr-x. The first character is the file type (- for a regular file, d for a directory, l for a symbolic link), and the next nine are the permissions in user, group, other order.
The octal sum
Each switch has a fixed value. Add the values that are on to get one digit per class.
digit = sum of the bits that are on (0 to 7)
Worked example: rwxr-xr-x.
- Owner
rwx: 4 + 2 + 1 = 7 - Group
r-x: 4 + 0 + 1 = 5 - Others
r-x: 4 + 0 + 1 = 5 - Result:
chmod 755
Going the other way is just as quick. To decode 640, split it into 6, 4 and 0. Six is 4 + 2, so the owner can read and write. Four is read only, so the group can read. Zero means others get nothing: rw-r-----.
Modes you will meet most
| Octal | Symbolic | Typical use |
|---|---|---|
| 644 | rw-r--r-- | Ordinary files such as HTML, CSS and images |
| 755 | rwxr-xr-x | Directories and scripts other users may run |
| 600 | rw------- | Private keys and files with secrets |
| 700 | rwx------ | A private directory such as ~/.ssh |
| 640 | rw-r----- | Config files a service group must read |
| 775 | rwxrwxr-x | Shared directories for a team group |
On a directory the bits mean slightly different things. Read lets you list the names inside, write lets you create, rename and delete entries, and execute lets you enter the directory and reach files by path. A directory with read but no execute shows names you cannot open.
Symbolic mode: change one bit at a time
You do not have to restate all nine bits. Symbolic mode adds or removes specific permissions and leaves the rest alone:
chmod u+x deploy.sh # owner may now execute
chmod go-w notes.txt # remove write from group and others
chmod a=r report.pdf # everyone: read only
chmod -R u+rwX,go+rX site/ # capital X: execute only on directories
The fourth digit and umask
A leading fourth digit sets the special bits: 4 for setuid, 2 for setgid and 1 for the sticky bit. The shared /tmp directory is normally 1777, so anyone can write there but only an owner can delete their own files. New files get their starting mode from umask, which removes bits from 666 for files and 777 for directories. With the common umask 022 a new file is 644 and a new directory is 755. With umask 027 they become 640 and 750.
Common mistakes
- Using 777 to make an error go away. It lets every account on the machine change the file. Find which user really needs access and fix the owner with
chowninstead. - Running
chmod -R 644on a tree. Directories lose their execute bit and become impossible to enter. Useu+rwXstyle orfindwith-type fand-type dseparately. - Loose SSH key modes. The SSH client refuses a private key that group or others can read. Use 600 for the key and 700 for the folder.
Questions
Why is it called octal?
Each digit holds three bits, and three bits can count from 0 to 7. Base 8 is octal, so each class fits in exactly one octal digit.
Does Windows use these numbers?
Not natively. Windows uses access control lists. You will still see chmod modes in WSL, in Git (which tracks only the execute bit) and on most web hosts.
Does this calculator change any file?
No. It only does the arithmetic in your browser. You copy the command and run it yourself.