What this chmod calculator does
Every file and directory on Linux, macOS and other Unix-like systems has a set of permission bits that say who can read, write and execute it. chmod changes them. The bits can be written two ways: as an octal number such as 755, or as letters such as rwxr-xr-x. This calculator converts between the two, builds both forms of the chmod command, and explains in plain English what the mode allows. Everything runs in your browser.
How octal permissions work
There are three classes of user: the file's owner (u), its group (g) and others (o), meaning everyone else. Each class gets one octal digit, made by adding read (4), write (2) and execute (1). Because each digit holds exactly three bits, octal maps neatly onto rwx.
| Digit | Letters | Meaning |
|---|---|---|
| 7 | rwx | read, write and execute |
| 6 | rw- | read and write |
| 5 | r-x | read and execute |
| 4 | r-- | read only |
| 3 | -wx | write and execute |
| 2 | -w- | write only |
| 1 | --x | execute only |
| 0 | --- | no access |
So chmod 755 is rwxr-xr-x: the owner has 4+2+1, and the group and others have 4+1. chmod 644 is rw-r--r--: the owner can read and write, and everyone else can only read. chmod 777 is rwxrwxrwx, full access for every user on the system.
On a directory, the same bits mean something different. Read lets you list the names inside, write lets you add, delete and rename entries, and execute (also called search) lets you enter the directory and reach the files in it. A directory usually needs execute wherever it has read, which is why directories are often 755 while the files inside are 644.
Special bits: setuid, setgid and sticky
A fourth, leading octal digit holds three special bits. In ls -l output they replace the execute character, in lowercase when execute is also set and in uppercase when it is not.
| Bit | Octal | Shown as | Effect |
|---|---|---|---|
| Setuid | 4000 | s or S in the owner's execute place | An executable runs with the file owner's user ID. Linux ignores it on scripts. |
| Setgid | 2000 | s or S in the group's execute place | An executable runs with the file's group ID. On a directory, new files take the directory's group and new subdirectories inherit the setgid bit. |
| Sticky | 1000 | t or T in the others' execute place | On a directory, only a file's owner, the directory's owner or root can delete or rename that file. |
For example, /tmp is normally 1777, shown as drwxrwxrwt: anyone can create files, but nobody can delete someone else's. A shared team directory set to 2775 shows as drwxrwsr-x, and files created in it belong to the directory's group rather than the creator's primary group. An uppercase S, as in rwSr--r-- (4644), means the setuid bit is set on a file nobody can execute, so it has no effect.
Umask and default permissions
New files don't start with 777. A program asks for a mode when it creates a file, usually 666 for files and 777 for directories, and the system clears every bit that is set in the process's umask. The result is mode & ~umask, a bitwise operation rather than a subtraction.
| Umask | New files | New directories |
|---|---|---|
022 | 644 rw-r--r-- | 755 rwxr-xr-x |
002 | 664 rw-rw-r-- | 775 rwxrwxr-x |
027 | 640 rw-r----- | 750 rwxr-x--- |
077 | 600 rw------- | 700 rwx------ |
The difference from subtraction shows with umask 033: new files get 644, not 666 − 033 = 633, because the execute bits it clears were never requested for files. Directories get 744.
The umask also affects chmod itself when a symbolic mode leaves out the u, g, o or a part. With umask 022, chmod +w file adds write for the owner only, and chmod -w file leaves the group and others' write bits alone. Write chmod a+w or chmod a-w to change every class regardless of the umask. Octal modes and the symbolic commands this tool generates name every class, so the umask does not change them.
Common mistakes
- Using 777 to fix a "Permission denied" error. It lets any user on the system change or replace the file. Check which user needs access and grant only that, often by changing the owner or group with
chownorchgrp. - Running
chmod -R 644on a directory tree. It removes execute from the directories as well, so nobody can enter them. Use a capitalX, which adds execute only to directories and to files that already have an execute bit:chmod -R u=rwX,go=rX dir. - Expecting
chmod 755to clear setgid on a directory. GNU chmod keeps a directory's setuid and setgid bits unless you name them. Usechmod g-s dir,chmod =755 dirorchmod 00755 dir.