Main menu

What is sticky Bit in Linux System

What is a sticky Bit in Linux System : Sticky Bit is used to prevent accidentally deletion of files and directories without it’s owner permission. Let’s say you have a directory and other people have write permission on it, but you don’t want them to delete directory and it’s contents. You can prevent this by enabling the sticky bit on that directory then only owner and root have the permission to delete them.

Add sticky bit on a directory

$chmod +t <directory_name>

or you can use hex permission  to define the sticky bit using 1 before you permission.

$chmod 1777 <directory_name>

Find sticky bit enabled directory.

find . -perm -1000

Where . define the search on current directory and -perm defines that sticky bit 1 should be enable

Exercise : Create a directory and put some content on it. Assign write permission to everyone. Enable the sticky bit on it. Switch user except user and try to remove content from sticky bit enabled directory.