Sticky bits are mainly set on directories.
If you give 777 (full permission) to any directory then all users can delete,modify all files and directories so to avoid this we use sticky bit. by using it, all users can create and modify their own directories or files not others
If the sticky bit is set for a directory, only the owner of that directory or the owner of a file can delete or rename a file within that directory.
The following two commands are used to apply sticky bit on any directory
chmod +t directory_name
OR
chmod 1777 directory_name
chmod +t directory_name
OR
chmod 1777 directory_name
Example:
Consider you have a directory "sticky ".
Consider you have a directory "sticky ".
drwxr-xr-x 2 user1 user1 4096 Jul 10 12:07 sticky
chmod it to " 777 ". This gives permissions for all the users to read, write and execute.
as: #chmod 777 /sticky/
then check
drwxrwxrwx 2
user1 user1 4096 Jul 10 12:07 sticky
Then Apply Sticky bit
drwxrwxrwt 2 root root 4096 Jul 10 12:07 sticky
From the above example user1 is the owner of the sticky directory. then create some files and folders and check
-rw-rw-r-- 1
user2 user2 0 Jul 10 12:26 test2
-rw-rw-r-- 1 user4 user4 0 Jul 10 12:27 test3
user4 can delete or modify only file test3
No comments:
Post a Comment