Tuesday, January 23, 2018

Advanced File Permissions in Linux (Sticky Bit)


Advanced File Permissions in Linux

There are 3 special attributes other than the common read/write/execute.

1. Sticky bit
2. Set User ID (SUID)
3. Set Group ID (SGID)


Example:

drwxrwxrwt - Sticky Bits - chmod  1777
drwsrwxrwx - SUID set -   chmod  4777
drwxrwsrwx - SGID set -   chmod  2777


Here we will discuss about Sticky bit

Sticky bit


Sticky bits are mainly set on directories. 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.


PRACTICAL STEPS TO UNDERSTAND STICKY BIT

Create a directory

[root@localhost]# mkdir /test


Check permissions of this directory

[root@localhost]#ls -la /


Now change permissions of this directory

[root@localhost]# chmod 777 /test

(This gives permissions for all the users to read, write and execute)


Check again permissions of this directory

[root@localhost]#ls -la /


Set Sticky Bit of this directory

[root@localhost]# chmod +t /test

Now only owner of directory or owner of file can rename or delete files in this directory


Check again permissions of this directory


[root@localhost]#ls -la /





Open a new terminal

login u1 user

[u1@localhost]$ 

create a file named file1 in /test 

[u1@localhost]$ vim file1 /test

Note: only owner of directory (root) or u1 can rename or delete file1


Open a new terminal

login u2 user

[u2@localhost]$ 

create a file named file2 in /test 

[u2@localhost]$ vim file2 /test

Note: only owner of directory (root) or u2 can rename or delete file2. u2 can not rename or delete file1 of u1.













1 comment: