What chmod 4755 means
| Who | Digit | Letters | On a file | On a directory |
|---|---|---|---|---|
| owner | 7 |
rwx |
Can read, modify and run | Can list files, create, delete and rename files and enter it and open files |
| group | 5 |
r-x |
Can read and run | Can list files and enter it and open files |
| others | 5 |
r-x |
Can read and run | Can list files and enter it and open files |
Each digit is the sum of read (4), write (2) and execute (1), and the leading digit sets the special bits: setuid (4), setgid (2) and sticky (1). In
ls -l output it looks like this:
$ ls -l
-rwsr-xr-x 1 alice staff 1834 Oct 21 10:30 example.txt
- The owner can read, write and execute.
- The group can read and execute.
- Everyone else can read and execute.
- Setuid: the file runs with the owner’s privileges.
When to use 4755
- passwd, sudo, ping (on older systems)
- Rarely needed for your own programs
Setuid makes an executable run with its owner’s privileges, so a root-owned 4755 binary runs as root for every user. That is how passwd can update /etc/shadow. Every setuid binary is a potential privilege escalation, so audit them with find / -perm -4000 -type f 2>/dev/null. Linux ignores setuid on scripts.
Is chmod 4755 safe?
Only for small, carefully audited programs. Any bug in a setuid program can let a user gain its owner’s privileges.
Commands
# One file
chmod 4755 file
# Same thing in symbolic form
chmod u=rwxs,g=rx,o=rx file
# Every file under a tree (leaves directories alone)
find /path/to/dir -type f -exec chmod 4755 {} +
# Check the result
stat -c '%a %A %n' file # Linux
stat -f '%Lp %Sp %N' file # macOS
Avoid chmod -R 4755 on a whole tree: it gives files and directories the same mode. The
find form above changes only files.
Other chmod values
777 · 775 · 770 · 755 · 751 · 750 · 744 · 711 · 700 · 666 · 664 · 660 · 644 · 640 · 600 · 555 · 500 · 444 · 400 · 000 · 1777 · 2775
Need a different combination? Use the Chmod Calculator.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What does chmod 4755 mean?
chmod 4755 sets the permissions to rwsr-xr-x. The owner can read, write and execute. The group can read and execute. Everyone else can read and execute. Setuid: the file runs with the owner’s privileges.
Is chmod 4755 safe?
Only for small, carefully audited programs. Any bug in a setuid program can let a user gain its owner’s privileges.