How to set a Directory Sticky Bit in Linux

There are times on Linux / Unix that you need to set the permissions on a directory so that only the owner and root can delete / rename files or sub-directories in the directory. This is true by default with the /tmp directory.

This is commonly referred to as the sticky bit.

If you want to keep the permissions the same on the directory and just add the sticky bit you can do this by using the chmod command with +t option.

chmod +t /tmp

We can see the results by using ls -al and we see t at the end of the output.

drwxrwxrwt.  25 root root  4096 Oct  3 07:33 tmp

We can also set the permissions and the sticky bit using octal numbers with chmod. Using 1 and then the octal permissions is the way to achieve this.

chmod 1777 /tmp

With the same results.

drwxrwxrwt.  25 root root  4096 Oct  3 07:33 tmp

You can remove the sticky bit by passing -t.

chmod -t /tmp

With the results.

drwxrwxrw.  25 root root  4096 Oct  3 07:33 tmp

Hope you find this helpful!


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.