- 1View File Permissions in Linux
- 2Change File Permissions with chmod in Linux
- 3How to Use Numeric Mode with chmod in Linux
- 4chmod Symbolic Mode in Linux
- 5How to Change File Ownership in Linux
- 6How to Change Group Ownership Using chgrp in Linux
- 7Understanding Linux File Permission Symbols (r, w, x)
- 8Linux File Permissions - User, Group, Others
- 9Understanding Special Permissions in Linux: SUID, SGID, and Sticky Bit
- 10How to Use ACLs in Linux - Set File Permissions
- 11Set ACL Permissions in Linux with setfacl
- 12How to View ACLs using getfacl in Linux
- 13Find Files by Permissions in Linux
Understanding Special Permissions: SUID, SGID, and Sticky Bit
Understanding Special Permissions: SUID, SGID, and Sticky Bit
Hey there, and welcome back to Program Guru! In this Linux tutorial, we're going to break down a topic that might sound scary at first—special permissions.
Don’t worry, I’ll explain it like you’ve never heard of them before. We’ll go through what they are, when to use them, and how to test them with real commands.
🔐 What Are Special Permissions?
In Linux, we usually talk about read (r), write (w), and execute (x) permissions for files and directories.
But there are three special permissions that give extra behavior to files or directories:
- SUID – Set User ID
- SGID – Set Group ID
- Sticky Bit
Let’s understand each with examples.
👤 SUID – Set User ID
When a file has the SUID permission, it runs with the permissions of the file owner, not the user who runs it.
Let’s check if any file already uses it:
ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 54256 /usr/bin/passwd
Notice the s
in place of the user’s execute bit: rws
. That’s SUID!
This allows normal users to change their password (which updates /etc/shadow
, owned by root), safely.
To add SUID to a custom file:
chmod u+s myscript.sh
To remove it:
chmod u-s myscript.sh
👥 SGID – Set Group ID
When applied to a directory, all new files inside it inherit the directory's group.
This is useful for shared folders.
Create a shared directory:
mkdir shared-folder
chmod g+s shared-folder
Check the permissions:
ls -ld shared-folder
drwxr-sr-x 2 user group 4096 Jul 2 12:00 shared-folder
The s
in the group section shows SGID is set.
On a file, SGID causes the program to run with the group ID of the file, just like SUID but for groups.
To add SGID:
chmod g+s myscript.sh
To remove it:
chmod g-s myscript.sh
📌 Sticky Bit
The sticky bit is used mostly on directories, like /tmp
.
It means: only the file owner or root can delete files in the directory—even if others have write access.
Without the sticky bit, anyone could delete any file!
Let’s apply it to a directory:
mkdir project-temp
chmod +t project-temp
Verify it:
ls -ld project-temp
drwxrwxrwt 2 user group 4096 Jul 2 12:15 project-temp
The t
at the end shows the sticky bit is active.
To remove it:
chmod -t project-temp
💡 Summary Table
Permission | Applies To | Effect | Symbol |
---|---|---|---|
SUID | File | Runs as file owner | s (user) |
SGID | File / Directory | Runs as file group / Inherit group | s (group) |
Sticky Bit | Directory | Only owner can delete files | t (others) |
🎯 Pro Tip
You can use octal notation for special permissions:
chmod 4755 file
– SUIDchmod 2755 file
– SGIDchmod 1755 file
– Sticky bit
The first digit (4, 2, or 1) sets the special permission.
🎉 That’s It!
Now you know what SUID, SGID, and the Sticky Bit are—and how to test them yourself. Practice using them safely in test directories first.
Thanks for watching, and I’ll see you in the next Linux tutorial!
Next Topic ⮕How to Use ACLs in Linux - Set File Permissions
Comments
Loading comments...