setuid, setgid and sticky bits with chmod
Meaning of the setuid, setgid and sticky bits in chmod octal modes on Linux.
The setuid, setgid and sticky bits are set with an extra digit placed in front of the octal mode used by chmod. The table below summarises the possible values.
Values of the special digit
| Digit | Active bits |
|---|---|
| 0 | None (setuid, setgid and sticky off) |
| 1 | Sticky |
| 2 | setgid |
| 3 | setgid and sticky |
| 4 | setuid |
| 5 | setuid and sticky |
| 6 | setuid and setgid |
| 7 | setuid, setgid and sticky |
Effect on a directory
- Sticky: only the owner of a file can delete or rename it inside the directory. This is the typical case of
/tmp, where users can create files but cannot remove or rename files owned by others. - setgid: files created in the directory inherit the directory's group, not the primary group of the user who creates them.
- setuid: no particular meaning on a directory.
Effect on an executable file
- setuid: the process runs with the permissions of the user who owns the file, not those of the user who launches it.
- setgid: the process runs with the permissions of the group that owns the file.
- sticky: historically, it kept the program in memory after it ran. This use is obsolete on modern systems.