piatok 11. februára 2022

chmod sticky bit

 Let me explain how to work chmod +t. 

You know about permissions a lot of! Chmod 777 and you cannot delete files in directory? Why? Please check for output ls -l? Do you see -t permission? 




t permission is sticky bit. When we set sticky bit, only owner has use permission write on file. Noboady can write files in this dicectory only owner. 


write  to file = vi (edit), touch, rm, rm -rf 


write to file (with sticky bit) = vi (edit), touch, rm, rm -rf only owner even though chmod 777 to directory


1) How to check? (you see t)


[root@station ~]# ll /mnt/

total 0


drwxr-xr-t 2 root root  6 Feb  5 11:29 test


2) How to set? 


[root@station ~]# chmod +t /mnt/test/


[root@station ~]# chmod 1777 /mnt/test/


3) How to works? 


a) audrey create file

[audrey@kosice ~]$ touch /mnt/test/1.txt

[audrey@kosice ~]$ ll /mnt/test/1.txt

-rw-rw-r-- 1 audrey audrey 0 Feb  5 11:31 /mnt/test/1.txt


b) michael create file

[michael@kosice ~]$ touch /mnt/test/2.txt

[michael@kosice ~]$ ll /mnt/test/

total 0

-rw-rw-r-- 1 audrey  audrey  0 Feb  5 11:31 1.txt

-rw-rw-r-- 1 michael michael 0 Feb  5 11:31 2.txt


c) michael wanted remove the file

[michael@kosice ~]$ rm -rf /mnt/test/1.txt

rm: cannot remove '/mnt/test/1.txt': Operation not permitted





d) michael wanted to edit the file

[michael@kosice ~]$ echo I am hacker >>  /mnt/test/1.txt

-bash: /mnt/test/1.txt: Permission denied


e) michael creted new file

[michael@kosice ~]$ echo I am very bad hacker! God Dammit > /mnt/test/3.txt
[michael@kosice ~]$ cat /mnt/test/3.txt
I am very bad hacker! God Dammit
[michael@kosice ~]$

Žiadne komentáre:

Zverejnenie komentára