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.
1 |
chmod +t /tmp |
We can see the results by using ls -al and we see t at the end of the output.
1 |
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.
1 |
chmod 1777 /tmp |
With the same results.
1 |
drwxrwxrwt. 25 root root 4096 Oct 3 07:33 tmp |
You can remove the sticky bit by passing -t.
1 |
chmod -t /tmp |
With the results.
1 |
drwxrwxrw. 25 root root 4096 Oct 3 07:33 tmp |
Hope you find this helpful!
Leave a Reply