- Home
- Tools
- Developer Tools
- Chmod Calculator
Chmod Calculator
Tick read, write and execute to get the numeric and symbolic Unix permissions.
| Read (4) | Write (2) | Execute (1) | Digit | |
|---|---|---|---|---|
| Owner | 7 | |||
| Group | 5 | |||
| Others | 5 |
A program runs with the rights of the file's owner.
A program runs with the file's group. In a directory, new files get the directory's group.
In a directory, users can't delete or rename each other's files.
Owner can read, write and execute. Group and others can read and execute.
chmod 755 filechmod u=rwx,g=rx,o=rx fileCommon values
How the number is built
A file has three sets of permissions: one for its owner, one for its group and one for everybody else. Each set is a single digit, the sum of read (4), write (2) and execute (1).
| Digit | Letters | Sum |
|---|---|---|
| 7 | rwx | 4 + 2 + 1 |
| 6 | rw- | 4 + 2 |
| 5 | r-x | 4 + 1 |
| 4 | r-- | 4 |
| 0 | --- | nothing |
So 640 is 6 for the owner (read and write), 4 for the group (read) and 0 for others: rw-r-----. The digits 3, 2 and 1 (-wx, -w-, --x) exist too, but are rare.
You can paste the permissions from ls -l straight into the symbolic field, with or without the first character that gives the file type.
The same bits mean something else on a directory
| On a file | On a directory | |
|---|---|---|
| Read | Read its contents | List the names in it |
| Write | Change its contents | Create, rename and delete files in it |
| Execute | Run it as a program | Enter it and reach the files inside |
This is why a directory almost always has execute wherever it has read: without it you can see the names and nothing else. It also explains why you can delete a file you aren't allowed to write to. Deleting changes the directory, so the directory's permissions decide.
A script needs read as well as execute, because the interpreter has to open the file. A compiled program runs with execute alone.
Usual values
| Mode | Used for |
|---|---|
| 644 | Ordinary files: the owner edits, everyone can read |
| 755 | Directories, and programs and scripts that anyone may run |
| 600 | Private files. SSH refuses to use a private key that others can read |
| 700 | Private directories such as ~/.ssh |
| 664, 775 | Files and directories that a group works on together |
New files get their mode from the umask. With the common umask of 022, files are created as 644 and directories as 755.
The fourth digit
A digit in front sets three special bits, added up the same way.
- Setuid (4): a program runs with the rights of the file's owner instead of the user who starts it.
passwdis the standard example. Linux ignores the bit on scripts. - Setgid (2): a program runs with the file's group. On a directory, new files inherit the directory's group, which keeps a shared folder consistent.
- Sticky (1): in a directory, a file can only be deleted or renamed by its owner, the directory's owner or root.
/tmpis 1777 for that reason.
In ls -l they take the place of the x: rwsr-xr-x is 4755, rwxr-sr-x is 2755 and rwxrwxrwt is 1777. A capital S or T means the special bit is set but the execute bit under it is not.
One GNU quirk: chmod 755 on a directory leaves a setgid or setuid bit that is already there in place. To remove it, say so with chmod g-s or chmod u-s.
Before you reach for 777
A "permission denied" error usually means the file belongs to the wrong user or group, and chown or chgrp is the fix. 777 makes the error go away by letting every account on the machine change the file.