Explain the three special privileges in Linux: SUID, SGID, and Sticky Bit, with a real-life use case for each.
SUID (octet 4000) makes the executable file run with the privileges of the file owner (usually root) rather than the user who ran it (example: passwd command). SGID (value 2000) on the folder makes any new file created within it automatically inherit the folder set instead of the creator's base set (example: team coworking folder). Sticky Bit (value 1000) on the folder prevents any user from deleting or renaming a file unless The owner of the file itself or root (example: /tmp folder).
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Special privileges table in Linux:
| Validity | Octal value | Behavior on files | Behavior on folders | Famous example |
|---|---|---|---|---|
| SUID | 4000 |
Operates as File Owner | No practical effect /usr/bin/passwd (to write the password in /etc/shadow) |
|
| SGID | 2000 |
Operates with FileSet | permission Any new file inherits folder set | Shared developer folders /var/share/project |
| Sticky Bit | 1000 |
No practical effect Only the real owner and root can delete the file | Temporary files folder /tmp |
- The appearance of a small
s: the special permission is activated and the execution permissionxalready exists. - Large
Sappears: The special permission is enabled but the execution permissionxdoes not exist (configuration error).
Security audit command to detect suspicious SUID files:
find / -perm -4000 -type f 2>/dev/null- Granting SUID privileges to Bash scripts or interactive compilers such as Python or Perl, opening a Privilege Escalation vulnerability for any local user.
- The belief that rwxrwxrwx permission on a folder without Sticky Bit protects files; any user with write permission on the folder can delete someone else's files even if they do not have read permission for those files.
- How do you search the system for all files with SUID permission for security auditing?
- What does the appearance of a lowercase s versus an uppercase S in the output of the ls -l command mean for a SUID or SGID authority?
How does umask work in Linux, and what are the default permissions for a newly created file and folder if umask is 022?
The umask value acts as a Permission Mask that subtracts the permissions specified in it from the default maximum permissions (666 for files and 777 for folders). If umask is 022, the permission of the new file becomes: 666 - 022 = 644 (rw-r--r--), and the permission of the new folder becomes: 777 - 022 = 755 (rwxr-xr-x).
Detailed Technical Explanation & PracticeExpand DetailsCollapse Details
Power calculation formula:
- Maximum folder validity:
777(rwxrwxrwx) - Maximum file validity:
666(rw-rw-rw-)
Application of mask 022:
777 (maximum volume)
- 022 (umask)
───────
755 (resulting folder validity: rwxr-xr-x)
666 (maximum file)
- 022 (umask)
───────
644 (resulting file validity: rw-r--r--)If the value of umask is 027:
- Folder:
777 - 027 = 750(rwxr-x---) - File:
666 - 027 = 640(rw-r-----) This prevents other server users from reading or writing any new file the user creates.
- Belief that maximum file permissions start with 777; default file permissions in Linux never grant execution permission x as a security precaution, and start with 666.
- The belief that calculation is always done by simple arithmetic subtraction; it is actually a bitwise AND with mask complement (AND NOT).
- What does the file and folder expiry become if umask is changed to 027 in a stressed production environment?
- Where is the global umask value set for all users in the system?