chmod 4755: The setuid Bit and What It Actually Does
4755 is rwsr-xr-x: the ordinary 755 mode plus the setuid bit. A program with setuid set runs with the effective user id of the file's owner rather than of the person who started it, which is how an unprivileged user runs a privileged operation.
At a glance
- Octal
- 4755. The leading 4 is the setuid bit
- Symbolic
- u=rwxs,g=rx,o=rx
- On a file
- -rwsr-xr-x
- Effect
- The process runs with the effective user id of the file owner, not of the caller
- Ignored on
- Shell scripts on Linux, and any file system mounted with the nosuid option
- Lowercase s or capital S
- s means setuid with execute set. S means setuid with the execute bit missing, which does nothing useful
- In the calculator
- Available as the 4755 preset and as a setuid checkbox alongside the nine permission boxes
In detail
Setuid solves a real problem. Changing your own password means writing to a file only root may write, so /usr/bin/passwd is owned by root with the setuid bit set, and when you run it the process gets root's effective user id for the duration. The same trick is what lets ping open a raw socket and what historically let mount work for ordinary users.
It is also the classic privilege escalation surface. A setuid root binary with a buffer overflow, a shell injection, or a careless use of an environment variable hands root to anyone who can run it. That is why the number of setuid binaries on a modern system keeps shrinking, and why capabilities, which grant one specific privilege rather than the whole identity, are preferred for new code.
Two things silently disable it. Linux ignores setuid on interpreted scripts entirely, because the gap between the kernel checking the file and the interpreter opening it was exploitable, so a setuid shell script simply runs as you. And any file system mounted with nosuid ignores the bit, which is standard for removable media and for many container and temporary mounts.
The rendering tells you whether it is doing anything. Lowercase s in the owner position means setuid with the execute bit also set, which is the working combination. Capital S means the setuid bit is set while the owner execute bit is not, which is almost always an accident and achieves nothing, because there is nothing to execute.
Auditing for it is straightforward and worth doing periodically. A find across the file system for the setuid bit lists every binary that can run as someone else, and anything on that list that you did not expect deserves an explanation. The calculator flags setuid with a security warning for the same reason.
Examples
chmod 4755 /usr/local/bin/helper
chmod u=rwxs,g=rx,o=rx /usr/local/bin/helper$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root /usr/bin/passwd
The s in the owner execute position is the setuid bit.
Running it gives the process root's effective user id.find / -xdev -perm -4000 -type f -exec ls -l {} +
# setgid as well
find / -xdev -perm /6000 -type f -exec ls -l {} +Things that catch people out
- Setuid on a shell script does nothing on Linux. The kernel drops the bit for interpreted files, so the script runs with your own identity and the apparent privilege never materialises.
- Capital S in a listing means the setuid bit is set without the execute bit. It looks alarming and accomplishes nothing, and it usually comes from a chmod that set 4644 instead of 4755.
- A file system mounted nosuid ignores the bit completely, which is why a binary that works in one location fails silently when moved to a temporary or removable mount.
- Copying a setuid binary usually drops the bit, and restoring it by hand on a file you did not build is a good moment to ask whether it should be setuid at all.
Try it: Chmod Calculator
Tick the nine permission boxes, or type an octal or symbolic value, and get the three digit and four digit octal, the ls -l rendering and the exact chmod command back.
Chmod Calculator
LOCAL · Browser-OnlyCalculate Unix file permissions with an interactive chmod builder
Permission Matrix
| Entity | Read (4) | Write (2) | Execute (1) | Octal | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | rwx | |||
| Group (g) | 5 | r-x | |||
| Others (o) | 5 | r-x |
Special Bits
Advanced permission flags for executables and directories
Generated Permissions
755rwxr-xr-x-rwxr-xr-xchmod 755 filenamechmod u=rwx,g=rx,o=rx filenamePermission Breakdown
Owner (u)
7rwx- - Read files / list directory contents
- - Write / modify / delete
- - Execute / traverse directory
Group (g)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Others (o)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Common Permissions Reference
| Octal | Symbolic | Meaning |
|---|---|---|
777 | rwxrwxrwx | Full access for everyone |
755 | rwxr-xr-x | Owner full, others read and execute |
750 | rwxr-x--- | Owner full, group read and execute |
700 | rwx------ | Owner full access only |
666 | rw-rw-rw- | Read and write for everyone |
644 | rw-r--r-- | Owner read/write, others read only |
600 | rw------- | Owner read/write only |
555 | r-xr-xr-x | Read and execute for everyone |
444 | r--r--r-- | Read only for everyone |
400 | r-------- | Owner read only |
Related File permissions
All file permissions →chmod 2775: The setgid Bit on Directories and on Files
2775 adds the setgid bit to 775 so new files inherit the directory's group. The fix for shared directories where the team cannot edit each other's files.
chmod 755: The Standard Mode for Directories and Programs
755 gives the owner full control and everyone else read and execute. Why it is right for directories and executables and wrong for ordinary data files.
How to Read an ls -l Permission String Such as rwxr-xr-x
The ten characters at the start of an ls -l line decode to a file type and three permission classes. What s, S, t, T and a trailing plus mean.
Four Digit Octal Modes Against Three Digit Ones
The leading digit of a four digit mode carries setuid, setgid and the sticky bit. When 0755 and 755 differ, and what GNU chmod does to directories.
chmod 1777: The Sticky Bit and Why /tmp Needs It
1777 adds the sticky bit to a world writable directory so only a file's owner can delete it. The mode of /tmp and the fix for any shared drop directory.
The Execute Bit on a Directory Means Traverse, Not Run
On a directory, execute grants the right to resolve names through it and read grants the right to list them. Why a directory at 644 cannot be entered.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder