We have moved to www.dataGenX.net, Keep Learning with us.

Monday, January 02, 2012

How to Use Sticky Bit on Directory and File


1. Set the sticky bit on Directory
$ chmod 1777 dir

you can assign only sticky bit to an existing directory (without touching any other user, group and other privileges) using chmod command
$ chmod +t dir

dir has rwx permission to everybody, all other users are allowed to do create their files or directories under this directory. However, even when the sub-directories or files under dir is having rwx permission to everybody, only the owner of those can delete or rename those files and directory. Other users cannot delete or rename it because of sticky bit.

Please note that /tmp has sticky bit enabled by default. You might have not noticed that until now. Now you know why /tmp directory is supposed to have sticky bit enabled.

$ ls -ld /tmp
drwxrwxrwt 3 root root 4096 Jan 31 08:29 /tmp


To remove the sticky bit from a directory, do the following.

$ chmod -t dir

No comments :

Post a Comment