Chmod Calculator
Work out Unix file permissions in either direction: tick the boxes, type an octal mode such as 755, or paste a string from ls -l. The chmod command is ready to copy.
3 or 4 digits, each from 0 to 7: 755, 0644 or 4755.
Nine characters such as rwxr-xr-x, or the first column of ls -l such as -rw-r--r-- or drwxr-xr-x.
| Read 4 | Write 2 | Execute 1 | Digit | |
|---|---|---|---|---|
| Owner u | 6 | |||
| Group g | 4 | |||
| Others o | 4 |
What this mode allows
Replace file with your own path. On a directory, "run" means entering it and reaching the files inside.
About the Chmod Calculator
Every file and directory on Linux, macOS and other Unix-like systems carries a mode: a small set of bits saying who may read it, change it or run it. The chmod command sets that mode, and it accepts two notations, octal numbers such as 755 and letters such as u=rwx,g=rx,o=rx. This calculator converts between the two, the rwxr-xr-x string printed by ls -l, and a grid of tick boxes, and explains in a sentence what the result allows.
How to use it
- Tick the boxes for the access you want, or type a mode into either field. Everything else updates to match.
- To read an existing mode, paste the first column of
ls -l, for example-rw-r--r--. The leading character is the file type (-for a file,dfor a directory) and is ignored. - Read the sentence and any warning under the grid, then copy the numeric or symbolic command.
- Use Copy link to share a mode. The link carries only the octal number, as
?mode=755.
Three classes, three bits
Permissions are set separately for three classes of user: the owner of the file (u), members of the file's group (g), and others (o), meaning every other account on the system. Each class has three bits: read (r), write (w) and execute (x). Only one class applies to any one person. If you own the file, the owner bits decide; otherwise, if you are in its group, the group bits decide; otherwise the others bits do.
How the octal digits add up
Each class is written as one digit, made by adding 4 for read, 2 for write and 1 for execute. The three digits are then written in the order owner, group, others.
r-x = 4 + 0 + 1 = 5
rw- = 4 + 2 + 0 = 6
r-- = 4 + 0 + 0 = 4
rwxr-xr-x = 755
rw-r--r-- = 644
Execute on a file and on a directory
On a file, execute means the file can be run as a program. A script also needs read permission, because the interpreter has to read it; that is why a script started by a scheduled job (see the cron explainer) is usually 755 or 700. On a directory the bits mean something different. Read lets you list the names inside. Execute lets you enter the directory and reach the files in it. Write, together with execute, lets you create, rename and delete entries. Deleting a file therefore depends on the permissions of the directory that holds it, not on the file's own. Directories nearly always need execute wherever they have read, which is why they are 755 where files are 644.
Setuid, setgid and the sticky bit
A fourth digit in front holds three special bits, added up the same way.
- Setuid (4): a program with this bit runs with the identity of the file's owner, not of the person who started it. It is how
passwdcan update a file only root may write. Linux ignores it on scripts. - Setgid (2): a program runs with the file's group. On a directory it makes new files inherit the directory's group, which is useful for shared project folders.
- Sticky (1): in a directory, a file can be deleted or renamed only by its owner, the directory's owner or root.
/tmpis 1777 so that everyone can create files there without being able to remove each other's.
In ls -l these appear in the execute position as s or t. A capital S or T means the special bit is set but the execute bit underneath it is not.
Sensible permissions for a website
On shared hosting the usual settings are 644 for files and 755 for directories: you can change them, and the web server can read them. Configuration files holding secrets, such as wp-config.php or .env with a database password in it, are better at 600 when PHP runs under your own account, or 640 when the web server reaches them through the group. If one of those passwords is weak, the password generator will make a better one.
777 is never the fix. It lets every account and every process on the server rewrite your files, so one compromised site on the machine can alter another. When a script cannot write to a directory, the cause is nearly always ownership: the file belongs to a different user from the one the script runs as. Correct the owner, or give group write (775 or 664) to a group you share with it. Some servers, those using suEXEC for example, refuse outright to run a script that is writable by group or others.
Why SSH rejects a readable key
OpenSSH checks the mode of a private key before using it. If the group or others have any access, it prints "UNPROTECTED PRIVATE KEY FILE" and ignores the key. Set the key to 600 (or 400) and the ~/.ssh directory to 700. The server is strict too: by default it ignores authorized_keys if that file, ~/.ssh or your home directory is writable by group or others.
Umask
The umask decides the mode of newly created files. Programs normally ask for 666 on a new file and 777 on a new directory, and the umask lists the bits to take away. With the common umask of 022, files come out as 644 and directories as 755; with 077 they come out as 600 and 700. The umask affects creation only, and a numeric chmod sets exactly the mode you give it.
Limitations
- The mode is not the whole story. Access control lists (shown as a
+after the mode inls -l), SELinux or AppArmor policies and immutable flags can all grant or deny access on top of it, and root is not held back by read and write bits at all. - Only the owner of a file, or root, can change its mode. If
chmodsays "Operation not permitted", look at ownership first. - Windows does not use this model; NTFS has its own access control lists. File systems such as FAT and exFAT store no per-file permissions, so chmod has no lasting effect on them.
- Both commands normally set the mode exactly. There are two exceptions: on BSD and macOS the symbolic command does not clear a sticky bit that is already set, and GNU chmod leaves the setuid and setgid bits of a directory as they were, with either command, unless you remove them explicitly, for example with
chmod g-s. - The calculator cannot see your files. It describes what a mode means, not what is currently set on your server.
Privacy
The calculation runs in JavaScript in your browser. Nothing is sent to a server. The octal mode is placed in the page address so that a link reproduces what you see; no file names or paths are involved.
Common questions
What does chmod 755 mean?
chmod 755 gives the owner read, write and execute permission, and gives the group and everyone else read and execute only. Each digit adds 4 for read, 2 for write and 1 for execute, so 7 is rwx and 5 is r-x, which ls -l prints as rwxr-xr-x. It is the usual mode for directories and for scripts.
What does chmod 777 mean, and why is it risky?
chmod 777 gives read, write and execute permission to the owner, the group and every other account on the system. It is risky because any user or process on the machine can then change or replace the file, so on a shared server one compromised site can alter another. Correcting the file's owner, or using 775, is nearly always the better fix.
What does chmod +x do?
chmod +x adds execute permission to a file so that it can be run as a program or script, leaving the read and write bits as they were. Written like this it normally applies to the owner, the group and others; chmod u+x limits it to the owner. A script also needs read permission before it will run.
What is the difference between chmod and chown?
chmod changes a file's permissions, while chown changes who owns it. chmod sets the read, write and execute bits for the owner, the group and others; chown assigns the file to a different user or group, and changing the owner normally needs root. When a program cannot write to a file, the cause is often the wrong owner rather than the wrong mode.