linux下檔案的特殊許可權s和t

2021-07-05 13:34:06 字數 1874 閱讀 9522

先看看這兩個檔案的許可權:

[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

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...

linux 下檔案特殊許可權

linux特殊許可權 特殊許可權 s setuid 當乙個命令具有setuid許可權時,普通使用者在執行此命令時,將以這個命令所有者的身份執行,ll etc passwd etc shadow rw r rxx 1 root root 1795 sep 25 10 12 etc passwd r 1...

Linux下檔案的特殊許可權

檔案許可權 是指對檔案的訪問許可權,包括對檔案的讀 寫 刪除 執行等。linux 是乙個多使用者作業系統,因此 linux 將乙個檔案或目錄與乙個使用者和組聯絡起來。對於檔案的讀 r 寫 w 執行 x 許可權,我們比較熟悉了,為了引出後面特殊許可權,我們對目錄檔案的寫 w 許可權進行講解。首先需要明...