What Are Special Permission Bits?
- SUID (Set User ID)
Runs an executable with the file owner’s user ID. - SGID (Set Group ID)
Runs an executable with the owning group’s privileges. - Sticky Bit
Restricts deletion of files in shared directories to the file owner or root.
| Octal Prefix | Permission Bit | Effect |
|---|---|---|
| 4xxx | SUID | Execute file as file owner |
| 2xxx | SGID | Execute file as file’s group owner |
| 1xxx | Sticky Bit | Restrict deletion in directories |
1. Set User ID (SUID)
When SUID is set on an executable, the process runs with the file owner’s privileges. Common use cases includesu, passwd, and other administrative tools.
Step-by-Step
- Create a test file and view its default permissions:
- Enable SUID without execute for the owner (octal
4664):
The uppercase
S indicates SUID is set but the owner’s execute bit is not enabled.- Grant both execute and SUID for the owner (octal
4764):The lowercasesshows both SUID and execute bits are active.
Carefully review which binaries receive the SUID bit. Misconfigured SUID files can introduce security vulnerabilities.
2. Set Group ID (SGID)
SGID works similarly to SUID but applies to group privileges.Step-by-Step
- Create a test file and inspect permissions:
- Set SGID without group execute (octal
2664):- Uppercase
Sin the group’s execute position shows SGID is set but no execute.
- Uppercase
- Add both group execute and SGID (octal
2764):- Lowercase
sindicates SGID and execute bits are set for the group.
- Lowercase
3. Finding SUID/SGID Files
Quickly locate files with SUID or SGID bits:4. Sticky Bit on Directories
The sticky bit ensures that only the file owner (or root) can delete or rename files within a shared directory.Step-by-Step
- Create a directory and view its default permissions:
- Set the sticky bit with execute (octal
1777):- The lowercase
tshows both execute and sticky bits are set.
- The lowercase
- Demonstrate sticky without execute (octal
1666):- Uppercase
Tindicates sticky is set but execute is not.
- Uppercase