Linux File Permissions Explained
Special Permissions: setuid, setgid and the Sticky Bit
Beyond the nine rwx bits there are three special ones. You will encounter them when you inspect binaries and shared directories.
The special bits at a glance
| Bit | Symbol in ls -l |
Effect |
|---|---|---|
| setuid | s in owner slot |
Runs the program with the file owner's privileges |
| setgid | s in group slot |
On files: runs with the group's privileges. On directories: new files inherit the directory's group |
| sticky | t in others slot |
In a shared directory, only the owner (or root) can delete files |
Spotting them with ls -l
$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 68208 ... /usr/bin/passwd
The s where an owner x would be is setuid. passwd runs with root's powers so it can write to the password database, even when you run it as a normal user.
The sticky bit looks like a t:
$ ls -ld /tmp
drwxrwxrwt 20 root root ... /tmp
/tmp is writable by everyone, but the t means only the file owner can delete files there — preventing users from wiping each other's temp files.
Setting the special bits
chmod u+s program # setuid
chmod g+s shared-dir # setgid on a directory
chmod +t shared-dir # sticky bit
In octal, the special bits are a leading digit: setuid 4, setgid 2, sticky 1.
chmod 4755 program # setuid + rwxr-xr-x
chmod 1777 shared-dir # sticky + rwxrwxrwx (like /tmp)
Setuid on your own binaries is rare
Forgetting how setuid works is a classic security hole. Never set setuid on a script or a binary you do not fully control — it can escalate privileges for anyone who can run it.
The takeaway
If ls -l shows an s or a t, the file or directory is using a special permission bit. Now you know exactly what they mean and how to set — and avoid — them.
Try it
ls -l /usr/bin/passwd— spot therwsin the owner triadls -ld /tmp— spot the trailingtmkdir ~/shared && chmod +t ~/shared && ls -ld ~/shared
Advertisement