chmod 755 lets the owner read, change and run a file, while the group and everyone else can only read and run it (rwxr-xr-x). It is the normal setting for folders and scripts. chmod 644 (rw-r--r--) is the one for regular files, and chmod 777 gives every permission to everyone, which is why it is almost never a good idea. To turn any other number into letters, or the other way round, use the AIMRAN Tools chmod calculator.
What does chmod 755 mean?
On Linux and macOS every file and folder has three sets of permissions: one for the owner, one for the file’s group and one for others (every other user). Each set can include three permissions:
- r (read): see the contents.
- w (write): change or delete it.
- x (execute): run it as a program. On a folder it means being allowed to enter it.
The three digits in chmod 755 are, in order, owner, group and others. Each digit is a sum: read is 4, write is 2 and execute is 1. So:
- 7 = 4 + 2 + 1 = read, write and execute (
rwx). - 5 = 4 + 1 = read and execute (
r-x). - 5 = the same for others.
That is why chmod 755 script.sh and chmod u=rwx,g=rx,o=rx script.sh do exactly the same thing. With ls -l you will see -rwxr-xr-x: the first character is the type (- for a file, d for a directory) and the next nine are the permissions.
What each digit from 0 to 7 means
| Digit | Letters | Permission |
|---|---|---|
| 0 | --- |
None |
| 1 | --x |
Execute only |
| 2 | -w- |
Write only |
| 3 | -wx |
Write and execute |
| 4 | r-- |
Read only |
| 5 | r-x |
Read and execute |
| 6 | rw- |
Read and write |
| 7 | rwx |
Read, write and execute |
With this table you can read any three-digit permission. 750, for example, means everything for the owner, read and execute for the group and nothing for others.
What does chmod 644 mean?
chmod 644 gives read and write to the owner (6) and read only to the group and others (4). In ls -l it shows as -rw-r--r--. It is the usual permission for files that are not run as programs: HTML pages, images, stylesheets, documents or a website’s .htaccess.
The only difference from 755 is the x. A text file does not need execute permission, and giving it one adds nothing. A folder does need it: without x nobody can enter it, even with read permission. That is why the usual rule on a server is 755 for folders and 644 for files, which is also what the WordPress documentation recommends (or 750 and 640 if you want to shut out other users).
What does chmod 777 do, and why avoid it?
chmod 777 gives read, write and execute to the owner, the group and every other user on the system (rwxrwxrwx). It often turns up as a quick fix for “Permission denied”, and it does work, but only because it opens the door to everyone.
On a shared server or a website, that means any process can change or replace those files. The WordPress guide is blunt about it: no directory should ever be given 777, not even upload directories, and the worst outcome is someone uploading or modifying a file to run code and taking full control of the site.
If you hit a permissions error, check who owns the file with ls -l before reaching for 777. Quite often the web server runs as another user (www-data, for example) and what needs changing is the owner, with chown, not the permissions.
Most common chmod permissions
These are the ones in the calculator’s “Common permissions” list, plus 777 as an example of what not to use:
| Permission | As shown by ls -l |
What it is for |
|---|---|---|
| 644 | -rw-r--r-- |
Regular files |
| 755 | -rwxr-xr-x |
Directories and executables |
| 600 | -rw------- |
Private keys and files with passwords |
| 700 | -rwx------ |
Private directory (such as ~/.ssh) |
| 664 | -rw-rw-r-- |
File shared with the group |
| 775 | -rwxrwxr-x |
Group directory |
| 400 | -r-------- |
Read-only for the owner |
| 1777 | drwxrwxrwt |
Temporary directory (/tmp) |
| 777 | -rwxrwxrwx |
Everything for everyone: avoid it |
How to work out a permission with the chmod calculator
If you would rather not add it up in your head, the calculator does it and writes the command for you.
- Open tools.aimran.es/en/dev/chmod. It starts with 755 loaded.
- In the “Permissions” table, tick or untick Read, Write and Execute for Owner, Group and Others. The “Value” column shows each row’s digit.
- You can also type straight into the “Octal” field (3 or 4 digits from 0 to 7) or the “Symbolic” one. In the latter you can paste exactly what
ls -lgives you, first character included, such asdrwxr-xr-x. - To start from a typical value, click one in the “Common permissions” list.
- Under “File or directory”, type the name and turn on “Recursive (-R)” if it should apply to everything inside.
- Copy the “Command” (with numbers) or the “Command with letters”, for example
chmod u=rwx,g=rx,o=rx file.
How to apply 755 to folders and 644 to files
“chmod 755 recursive” is one of the most common searches. The trouble with chmod -R 755 folder is that it sets 755 on everything, files included, which then become executable for no reason. To treat folders and files separately, use find:
find /path/to/site -type d -exec chmod 755 {} +
find /path/to/site -type f -exec chmod 644 {} +
The first line only changes directories (-type d) and the second only files (-type f). If there are scripts inside that do need to run, give them their own chmod 755 afterwards.
SSH key permissions: 600 and 700
If SSH ignores your private key or warns that its permissions are too open, this is nearly always why. The ssh manual page says the private key should be readable by the user but not accessible by others, and that ssh will simply ignore a private key file if others can access it. For the ~/.ssh directory it recommends read, write and execute for the user only.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
The fourth digit: setuid, setgid and sticky
Sometimes you will see four-digit permissions such as 4755 or 1777. According to the chmod manual, the first digit holds the special bits: setuid is 4, setgid is 2 and sticky is 1. If you only write three digits, the missing one is taken as 0, so chmod 755 and chmod 0755 are the same.
- setuid (4): the program runs with its owner’s permissions. In
ls -lthe owner’sxbecomes ans. - setgid (2): the same, but with the group. On a folder, anything created inside inherits its group.
- sticky (1): on a folder, each user can only delete their own files. That is the case with
/tmp, set to 1777, which shows asdrwxrwxrwt.
In the calculator they are in the “Special bits” panel. If the s or t appears in capitals, the special bit is on but the execute permission underneath it is not.
Common mistakes
- Using
chmod -R 777to “fix” an error. It works, but leaves the folder open to any user. Check the owner withls -lfirst. - Removing
xfrom a folder. With 644 on a folder you cannot enter it or open what is inside, even if the files themselves have the right permissions. - Applying
-R 755to a whole website. Every file ends up executable. Use the twofindcommands above. - Leaving an SSH key on 644. SSH ignores it. Set it to 600.
- Changing permissions on a file you do not own. Only the owner or an administrator can; otherwise the command fails and you will need
sudo.
Conclusion
Three rules cover almost every case: 644 for files, 755 for folders and scripts, and 600 or 700 for anything that is yours alone, such as SSH keys. 777 is the exception worth avoiding. When you come across an odd number or a string like rwxr-x--- and are not sure what it means, paste it into the chmod calculator and it will give you the translation and a command ready to copy.