Who can do what
| Class | Read (4) | Write (2) | Execute (1) | On a directory |
|---|---|---|---|---|
| Owner (u) | Yes | Yes | Yes | List the files. Enter it and open files inside. Create, rename and delete files. |
| Group (g) | Yes | No | Yes | List the files. Enter it and open files inside. |
| Others (o) | Yes | No | Yes | List the files. Enter it and open files inside. |
When to use chmod 4755
Gives the owner full access and others read and execute, plus the setuid bit: the program runs with the permissions of the file's owner, not of the user who starts it.
How passwd and sudo work: they are owned by root and setuid, so ordinary users can run them with root privileges. Setuid on your own programs, and especially on scripts, is a serious security risk.
Special bits
- Setuid (4): an executable runs with the permissions of the file's owner instead of the user who started it.
Commands
Set the mode with octal digits, or with the equivalent symbolic form:
chmod 4755 path/to/file
chmod u=rwx,g=rx,o=rx,u+s path/to/fileTo apply it to every directory below a folder (and not to the files), combine it with find:
find path/to/folder -type d -exec chmod 4755 {} +chmod -R 4755 changes files and directories alike, which is rarely what you want: directories usually need execute, regular files usually should not have it.