linux下文件的特殊權限s和t

先看看這兩個文件的權限:
[root@localhost ~]# ls -ld /usr/bin/passwd  /tmp
drwxrwxrwt 4 root root  4096 Jun  2 17:33 /tmp
-rwsr-xr-x 1 root root 22984 Jan  7  2007 /usr/bin/passwd

這裏的s和t是針對執行權限來講的。
這個s權限,是爲了讓一般使用者臨時具有該文件所屬主/組的執行權限。就比如/usr/bin/passwd在執行它的時候需要去修改/etc/passwd和/etc/shadow等文件,這些文件除了root外,其他用戶都沒有寫權限,但是又爲了能讓普通用戶修改自己的密碼,只能時臨時讓他們具有root的權限。所以這個s權限就是用來完成這個特殊任務的。s權限只能應用在二進制的可執行文件上。
如果你不想讓普通用戶修改自己的密碼,只需要
[root@localhost ~]# chmod u-s /usr/bin/passwd  或者
[root@localhost ~]# chmod 0755 /usr/bin/passwd
0755最前面的0表示不使用任何特殊權限,該位上的數字可以是0,1(--t),2(-s-),3(-st),4(s--),5(s-t),6(ss-),7(sst)
那個t權限只針對目錄生效,它表示只能讓所屬主以及root可以刪除(重命名/移動)該目錄下的文件。比如/tmp目錄本來就是任何用戶都可以讀寫,如果別人可以任意刪除(重命名/移動)自己的文件,那豈不是很危險。所以這個t權限就是爲了解決這個麻煩的。下面舉一個例子,說明一下這個權限的用法:
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# mkdir test
[root@localhost tmp]# chmod 1777 test
[root@localhost tmp]# ls -ld test
drwxrwxrwt 2 root root 4096 Jun  2 18:10 test
[root@localhost tmp]# su test1
[test1@localhost tmp]$ touch test/1.txt
[test1@localhost tmp]$ ls -l test
total 4
-rw-r--r-- 1 test1 test 0 Jun  2 18:12 1.txt
[test1@localhost tmp]$ exit
[root@localhost tmp]# su www
[www@localhost tmp]$ ls -l test/1.txt
-rwxrwxrwx 1 test1 test 6 Jun  2 18:12 test/1.txt
[www@localhost tmp]$ rm test/1.txt
rm: cannot remove `test/1.txt': Operation not permitted
提示不能刪除1.txt
[www@localhost tmp]$ exit
[root@localhost tmp]# chmod -t test
去掉t權限。
[root@localhost tmp]# ls -ld test
drwxrwxrwx 2 root root 4096 Jun  2 18:13 test
[root@localhost tmp]# su www
[www@localhost tmp]$ rm -f test/1.txt
再次刪除,則刪除成功。
[www@localhost tmp]$ ls test/1.txt
ls: test/1.txt: No such file or directory
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章