Home > Wiki Tips

Sticky Bit Explained: What It Is, How It Differs from SUID?

Updated on Monday, March 10, 2025

iBoysoft author Yvonne Feng

Written by

Yvonne Feng
Professional tech editor

Approved by

Jessica Shee

English

Summary: This article from iBoysoft explains what a Sticky Bit is, the difference between SUID and a Sticky Bit, and how to set one.

summary-sticky-bit

In Linux and Unix-based operating systems, the Sticky Bit plays a crucial role in managing shared directories. It prevents users from deleting or modifying files owned by others in publicly writable directories. If you want to learn more about Sticky Bit, keep reading.

In this article, we'll take a closer look at what the Sticky Bit is, how it differs from SUID (Set User ID), and how to set it up.

What is a Sticky Bit?

The Sticky Bit is a special permission used in Unix-based operating systems, including Linux. It is typically applied to shared directories, such as /tmp, to prevent users with write access from deleting or modifying files owned by others, thus avoiding unintended data loss or disruption.

In essence, the Sticky Bit acts as a security safeguard in multi-user environments, allowing file owners to control their files while still permitting other users to write files in the same directory.

This permission setting is crucial for preventing both malicious and accidental file modifications, especially in directories where multiple users frequently interact. By restricting file deletion to the file owners, the Sticky Bit creates a safer and more predictable environment for managing temporary files and shared resources.

What is the difference between SUID and Sticky Bit?

SUID (Set User ID) and the Sticky Bit are both special file permissions in Unix systems, but they serve different purposes. SUID allows a user to execute a file with the privileges of the file's owner rather than the privileges of the user running the file. This permission is typically applied to executable files that require elevated privileges, such as the passwd command, which lets regular users change their passwords with root privileges.

The Sticky Bit, on the other hand, is applied to directories to control file deletion. When set in a directory, it ensures that only the file's owner (or the root user) can delete or rename files within that directory, even if other users have write permissions. The Sticky Bit is commonly used in shared directories, like /tmp, to prevent users from accidentally or maliciously deleting other people's files.

While both permissions improve system security, SUID focuses on controlling the execution of files with elevated privileges, while the Sticky Bit manages file deletions in shared directories. They enhance security in different areas: SUID for file execution and Sticky Bit for shared directory access.

Share the differences between SUID and Sticky Bit with your friends!

 

How to set the Sticky Bit?

After understanding the specific function of the Sticky Bit and how it differs from SUID, you should know that setting the Sticky Bit can enhance the security of shared directories. The process of setting the Sticky Bit is quite simple, and you can follow the steps below to set it in the Terminal.

  1. Open Terminal in Launchpad > Others > Terminal.
  2. Check if the Sticky Bit is already set: You can use the ls -ld /path/to/directory command to check the directory's permissions. If the Sticky Bit is set, the last character of the permissions will be t, for example, drwxrwxrwt
  3. Set the Sticky Bit: To set the Sticky Bit on a directory, use the following command:
    sudo chmod +t /path/to/directory For example, to set the Sticky Bit on the /tmp directory, run:sudo chmod +t /tmp 
  4. Verify the setting: After setting, use ls -ld /path/to/directory again to check the directory's permissions and ensure the Sticky Bit has been correctly applied.

Now, the Sticky Bit is set. Of course, if you need to remove the Sticky Bit, you can use the following command:

sudo chmod -t /path/to/directory

Share this article if you find it useful!