chmod 755 (rwxr-xr-x)
The owner can do everything; the group and everyone else can read and run, but not change. It is the standard mode for programs, scripts and ordinary directories.
This tool runs in your browser. We never send what you type or paste to a server.
What chmod 755 sets
| Who | Digit | Read | Write | Execute | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | yes | yes | yes | rwx |
| Group (g) | 5 | yes | no | yes | r-x |
| Others (o) | 5 | yes | no | yes | r-x |
chmod 755 file # numeric
chmod u=rwx,go=rx file # the same, in symbolic form
ls -l shows this mode as -rwxr-xr-x on a file and drwxr-xr-x on a directory. On a file, execute means it can be run as a program. On a directory, read lists the names inside, write creates, renames and deletes entries, and execute (search) is what lets you enter it and reach the files inside.
What it means for a file and for a directory
On a file, 755 makes a program anyone can run and read but only its owner can edit or replace. Most commands in /usr/bin look like this.
On a directory, 755 lets everyone list it and reach the files inside, while only the owner can add, rename or delete entries. Whether someone can then read a particular file inside is decided by that file's own mode.
When to use 755
- Shell scripts and compiled programs that several users, or a service account, need to run.
- Directories that should be browsable: a web root, a shared
bindirectory, project directories on a build server. - It is what you get by default. With the usual umask of
022, new directories are created as 755 and new files as 644.
A file needs the execute bit only if it is run directly, as in ./deploy.sh. A script you always start with bash deploy.sh or python app.py, and data files such as HTML, images and configuration, should be 644.
Is 755 safe?
Nobody but the owner can modify a 755 file, so it cannot be tampered with by other accounts. The exposure is in reading: every user on the machine can read the file, and can list and enter the directory.
- Do not use it on anything that holds secrets. A 755 script with a password or API key inside can be read by every local user; use 700 or 750.
- Who owns the file matters as much as the mode. A 755 file owned by the web server's own user can be rewritten by a compromised web application. Have a different user own the code and give the server read access only.
- A directory's write bit controls deletion. A 755 file inside a 777 directory can still be deleted and replaced by anyone.
Applying it without breaking things
The mistake to avoid is chmod -R 755 on a tree that contains ordinary files: it marks every file as executable. Set directories and files separately:
chmod 755 deploy.sh # one script
find site -type d -exec chmod 755 {} + # directories only
find site -type f -exec chmod 644 {} + # files only
chmod -R u=rwX,go=rX site # or both at once
The capital X in the last line adds execute to directories, and to files that are already executable for someone, and to nothing else.
755 compared with its neighbours
Questions
What is the difference between chmod 755 and chmod 777?
With 755 only the owner can change the file or the contents of the directory. With 777 every user on the system can, which lets any account or any compromised service modify or replace it. Use 755, and fix the ownership or the group if a program then cannot write where it needs to.
Should website files be 755?
Directories, yes. Files should normally be 644, because HTML, CSS, images and PHP scripts are read by the web server rather than executed directly. Files holding credentials should be tighter still, such as 640 or 600.
Why is my script "Permission denied" after chmod 755?
Check the things the mode does not cover: the file system may be mounted with noexec, a directory above the script may not be searchable by you, or the first line may point to an interpreter that does not exist. A script with Windows line endings fails in a similar way, with a "bad interpreter" message.