breakitdown

chmod 4755: setuid (rwsr-xr-x)

Answer

chmod 4755 is 755 plus the setuid bit (the leading 4). When anyone runs the program, it runs with the privileges of the file's owner rather than the user who started it. ls -l shows this as an s in the owner's execute slot: rwsr-xr-x.

Try

chmod 4755 = rwsr-xr-x: owner full access, everyone else read and execute, plus setuid.

Read 4Write 2Execute 1Digit
Owner (user)7
Group5
Others5
Special4
  1. 7
    Owner (user): 7 = 4 read + 2 write + 1 execute
  2. 5
    Group: 5 = 4 read + 1 execute
  3. 5
    Others: 5 = 4 read + 1 execute
  4. 4
    Special bits: 4 setuid: a program runs with its owner's rights, not the caller's

On a file

  • Owner (user) read it, change it and run it as a program
  • Group read it and run it as a program
  • Others read it and run it as a program

On a directory

  • Owner (user) list the names inside, enter it and open files by name, create and rename and delete entries
  • Group list the names inside and enter it and open files by name
  • Others list the names inside and enter it and open files by name

chmod 4755 filechmod u=rwxs,go=rx filels -l → -rwsr-xr-x

What to know

/usr/bin/passwd is 4755 and owned by root. That is how an ordinary user can change their own password: the program runs as root, writes to /etc/shadow (which the user cannot touch directly), and is written to only change the caller's own entry. sudo, su and mount use setuid the same way.

Every setuid-root program is a potential privilege escalation, so systems keep the list short. List them with find / -xdev -perm -4000 -type f.

Where it fits

Gotchas

Related explainers

← chmod calculator