chmod 755
The owner can do everything, everyone else can read and execute. The usual mode for directories, programs and scripts.
| 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
What 755 allows
| Who | Digit | On a file | On a directory |
|---|---|---|---|
| Owner | 7 rwx | read, change and run | list, enter, add and remove files |
| Group | 5 r-x | read and run | list and enter |
| Others | 5 r-x | read and run | list and enter |
ls -l shows this mode as -rwxr-xr-x on a file and as drwxr-xr-x on a directory.
The owner can change the file. Everybody else can use it and can't change it.
Where it belongs
- Directories. 755 is what
mkdirgives a new directory under the common umask of 022. Everyone can look around in it, only the owner can add or remove files. - Programs and scripts. The commands in
/usr/binare typically 755: root can replace them, every user can run them. - The directories of a website, so that the web server can read them without owning them. The files inside are usually 644.
Where it doesn't
On an ordinary file, such as a text or an image, the execute bits serve no purpose, and a data file that can be run by accident is one more thing that can go wrong. Those want 644. To put a whole tree in order, treat directories and files separately:
find . -type d -exec chmod 755 {} +
find . -type f -exec chmod 644 {} +
chmod -R 755 . would make every file executable as well.
The chmod calculator explains how the digits are built, and what setuid, setgid and the sticky bit add to them.