Saturday, August 13, 2016

What is a sticky Bit and how to set it in Linux?



What is Sticky Bit?

Sticky Bit is used mainly on folders in order to avoid deletion of a folder and its content by other user though he is having write permissions. If Sticky bit is enabled on a folder, the folder is deleted by only owner of the folder and super user(root). This is a security measure to suppress deletion of critical folders where it is having full permissions by others.

Use chmod command to set Sticky Bit on Folder: /opt/dump/

Symbolic way:
 
chmod o+t /opt/dump/
or 
chmod +t /opt/dump/
 
Let me explain above command we are setting Sticky Bit(+t) to folder /opt/dump by using chmod command.
 
Numerical way:
 
chmod 1757 /opt/dump/
 
Here in 1757, 1 indicates Sticky Bit set, 7 for full permissions for owner, 5 for read and execute permissions for group, and ful permissions for others.
 
Checking if a folder is set with Sticky Bit or not?
 
Use ls –l to check if the x in others permissions field is replaced by t or T
 
For example: /opt/dump/ listing before and after Sticky Bit set

Before Sticky Bit set:

ls -l
 
total 8
 
drwxr-xr-x 2 root root 4096 Oct 11 20:01 dump




After Sticky Bit set:

ls -l
 
total 8

drwxr-xr-t 2 root root 4096 Oct 11 19:45 dump

Removing Sticky bit

Symbolic way:

# chmod o-t /opt/dump
Or
# chmod –t /opt/dump

Numeric Way

# chmod 0755 /opt/dump

After Sticky Bit remove

drwxr-xr-x 2 root root 4.0K Oct 12 10:24 dump


No comments:

Post a Comment