What is Sticky Bit in Linux?
Sticky bit is a flag added to a directory/file to avoid removing/renaming it by any user other than the owner or root. Please check the below scenario:
Create a directory named “grepitout”
mkdir grepitout
Give all the users read-write-execute access to it
chmod 777 grepitout
Check the permission using the command below:
ls -ld grepitout
Output:
drwxrwxrwx 2 grepit grepit 4096 Feb 9 15:43 grepitout
Create different files in the directory as different users (get into the directory using “cd grepitout/”)
Please check the files and the ownership associated with them:
ls -la grepitout/ -rwxrwxrwx 1 grepit grepit 0 Feb 9 15:48 user1 -rwxrwxrwx 1 user1 user1 0 Feb 9 16:11 user1file -rwxrwxrwx 1 user2 user2 0 Feb 9 16:15 user2file
This means that the user2 can delete/rename files created by user1 and vice versa. Here we can set “Sticky Bit” to the directory using the command below:
chmod +t grepitout
You can check if the sticky bit is successfully added to the directory using the below command:
ls -ld grepitout drwxrwxrwt 2 grepit grepit 3096 Feb 9 16:19 grepitout
Please notice that “t” added at the end of the permission bit series “drwxrwxrwt”. You can remove the sticky bit using the command below:
chmod -t grepitout
That means +t to add sticky bit and -t to remove. Once the sticky bit is set the owner of the file can only be able to delete/rename the file/directory.
Read More:
- Understanding FTP ( File Transfer Protocol )
- How to restore and backup MBR in Linux
- Useful GIT Commands
- Configure NIC bonding in CentOS 7 / RHEL 7
- Difference between Hardlink and Softlink
- Understanding VI editor
- Understanding top Command
- How to add additional drive to CentOS server
- Linux File System Hierarchy
- How to avoid accidental deletion of files in Linux
- Useful Qmail Commands
- Useful Exim Commands
- Useful Postfix commands Linux
If you like the post Understanding top Command and wish to receive more articles from us, please like our FB page: GrepItOut
Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments. For more details on our services, please drop us an E-mail at info@grepitout.com
Add Comment