Sweshi's Tutorials

Linux Permissions

Linux Special Permissions: sticky bit

NB: This tutorial has worked on Centos 6,7,8 and 9

The sticky bit, when set on a directory, is a special permission that has different effects depending on the user's relationship to the directory. This permission is primarily used on directories where multiple users have write access, such as the /tmp directory. When the sticky bit is set on a directory, only the owner of a file within that directory can delete or rename the file, even if other users have write permissions in that directory. This is often used to secure the /tmp directory, ensuring that users can only delete their own files.

Special Permission Letter Representation Numerical (Octal) Representation Types of files it works on
sticky bit t 1 folders only
Examples of sticky bit using letter representation
how to add the sticky bit Linux Special Permission using chmod with letters

We can enable the sticky bit by using “o+t”. In this example, I enable it on the folder named “example” by running the command “chmod o+t example”. When we do a long listing using “ls -l”, we see that the letter “t” has been added to the “others” section of the permissions. This shows that the bit is enabled on the directory.

how to remove the sticky bit Linux Special Permission using chmod with letters

We can remove the sticky bit by running “o-t”. In this example, I have run the command “chmod o-t example” where example is the name of the folder. When we list using “ls -l”, we see that the letter “t” has been removed from the “others” section of the permissions. This shows that the bit had been removed.

Examples of sticky bit using numbers (octal) representation
how to add the sticky bit Linux Special Permission using chmod with numbers (octal)

We can use the number “1” to add the sticky bit to a directory. The “1” is added in front of the 3 standard permissions. As seen in this figure, I run the command “chmod 1755 example”. The leftmost “1” is the sticky bit, followed by 3 standard permissions. When we do a long listing “ls -l”, we see that the letter “t” is in the “others” section of the permissions showing that the bit is enabled.

how to remove the sticky bit Linux Special Permission with chmod using numbers (octal)

We can then remove the sticky bit by using zero “0” in front of the standard permisions. In this case I ran “chmod 0755 example” to remove the sticky bit from the “example” folder. When we do the listing using “ls -l”, we see that the letter “t” is removed, meaning that the sticky bit is disabled on the folder.


Video