Sticky bit is an extra permission option for files and folders in linux. There are two main reasons for using sticky bit.
If it is applied to a regular file, the file’s image is kept in the memory so that if the file is required to be open it is loaded quickly. The second reason for using sticky bit is about permissions. When sticky bit is set for a directory, owner of the directory will have permissions to delete all the files in that directory even if it has not ownership of a file.
If it is applied to a regular file, the file’s image is kept in the memory so that if the file is required to be open it is loaded quickly. The second reason for using sticky bit is about permissions. When sticky bit is set for a directory, owner of the directory will have permissions to delete all the files in that directory even if it has not ownership of a file.
An example makes it clear:
Say we have a directory named /sticky and two users named skipper and rico.
# whoami
root
# mkdir /sticky
# chown skipper:rico /sticky
# chmod 775 /sticky
#
# ls -la
drwxrwxr-x 2 skipper rico 4096 Jul 17 16:59 sticky
# chmod +t /sticky
# ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 16:59 sticky
#
# su – skipper
$ cd /sticky
$ touch skipper.file
$ ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 17:08 .
drwxr-xr-x 39 root root 4096 Jul 17 16:59 ..
-rw-rw-r– 1 skipper skipper 0 Jul 17 17:08 skipper.file
$ exit
#
# su – rico
$ cd /sticky
$ touch rico.file
$ ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 17:13 .
drwxr-xr-x 39 root root 4096 Jul 17 16:59 ..
-rw-rw-r– 1 rico rico 0 Jul 17 17:13 rico.file
-rw-rw-r– 1 skipper skipper 0 Jul 17 17:08 skipper.file
Now we can test permissions:
# whoami
root
# su – rico
$ cd /sticky
$ ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 17:13 .
drwxr-xr-x 39 root root 4096 Jul 17 16:59 ..
-rw-rw-r– 1 rico rico 0 Jul 17 17:13 rico.file
-rw-rw-r– 1 skipper skipper 0 Jul 17 17:08 skipper.file
$ rm -f skipper.file
rm: cannot remove ‘skipper.file’: Operation not permitted
$ exit
#
# su – skipper
$ cd /sticky
$ ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 17:13 .
drwxr-xr-x 39 root root 4096 Jul 17 16:59 ..
-rw-rw-r– 1 rico rico 0 Jul 17 17:13 rico.file
-rw-rw-r– 1 skipper skipper 0 Jul 17 17:08 skipper.file
$ rm -f rico.file
$ ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 17:25 .
drwxr-xr-x 39 root root 4096 Jul 17 16:59 ..
-rw-rw-r– 1 skipper skipper 0 Jul 17 17:08 skipper.file
$ rm -f skipper.file
$ ls -la
drwxrwxr-t 2 skipper rico 4096 Jul 17 17:26 .
drwxr-xr-x 39 root root 4096 Jul 17 16:59 ..
now we proved that the skipper (owner of the /sticky directory) can delete all files.
Comments
Post a Comment