USER ID and GROUP ID Permissions
To understand sticky bit and user permission in more depth let’s take an example. Create two user named vinita and nikita. And a example directory on root partitions.
#useradd vinita #passwd –d vinita #useradd nikita #passwd –d nikita #mkdir /example
As example directory is created by root so the owner and group of this directory will root. By default permission will be inherited to all other object created in this directory to root owner. Now we will use symbolic method to change the ownership issue to this directory.
#chmod ugo+rwxs /example #ls –ld /example
As you can see in image s bit is set in owner and group filed which will automatically set owner and group to their respective owner and group. To verify login form user nikita and change directory to example and creates a file.
$cd /example $cat > nikita_file This is the file of nikita $ls –l
As you can see owner filed is changed to user nikita.
Now create a file form user vinita.
$cd /example $cat > vinita_file This is file of Vinita $ls –ld
Now you can understand what s bit do in chmod command. This is best options when users are working on some shared project. As they will gets ownership of their files automatically.
Implementation of sticky bit
But this could create other problem. User can accidently or intensely delete other user’s files and folder as all user have full permission on this shared folder. Go on terminal where user Vinita is logged in and delete the file of nikita.
To control this behaviors switch to root user and set sticky bit on /example folder.
#chmod o+t /example #ls –ld /example
Sticky bit is defined by t options. As you can see in output other have t bit set in their filed. Now only owner of file and root user can delete file in this folder.
To verify switch Vinita user again and try to delete the files of nikita. This time it will not success this time.
To remove sticky bit use minus sign.
#chmod o-t /example
now Vinita can delete the files owned by nikita