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

PermissionApplies ToEffectSymbol
SUIDFileRuns as file owners (user)
SGIDFile / DirectoryRuns as file group / Inherit groups (group)
Sticky BitDirectoryOnly owner can delete filest (others)

🎯 Pro Tip

You can use octal notation for special permissions:

  • chmod 4755 file – SUID
  • chmod 2755 file – SGID
  • chmod 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!


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...