linux下檔案特殊許可權設定位S和沾附位T

2021-09-02 21:34:57 字數 2534 閱讀 2816

=

朝花夕拾~~好多年前看書有的知識了~~=

為了讓一般使用者臨時具有該檔案所屬主/組的執行許可權。比如/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)

只針對目錄生效,它表示只能讓所屬主以及root可以刪除(重新命名/移動)該目錄下的檔案。比如/tmp目錄本來就是任何使用者都可以讀寫,如果別人可以任意刪除(重新命名/移動)自己的檔案,那豈不是很危險,所以這個t許可權就是為了解決這個問題。

下面通過乙個例項來體會這個t許可權的用法:

(1) root使用者在/tmp目錄下建立乙個test目錄,並設定test目錄的相關許可權為1777(有特殊許可權t)

[root@localhost tmp]# mkdir

test

[root@localhost tmp]#

chmod

1777

test

[root@localhost tmp]#

ls -ld

test

drwxrwxrwt.

2 root root 4096 oct 12

22:31 test

(2) 切換到第乙個使用者zhangming,在test目錄下建立乙個新檔案aaa.txt,並寫入資料

[root@localhost tmp]# su

zhangming

[zhangming@localhost tmp]$

touch test/aaa.txt

[zhangming@localhost tmp]$

echo

"hello

" >> test/aaa.txt

[zhangming@localhost tmp]$

ls -l test

total

4-rw-rw-r--. 1 zhangming zhangming 6 oct 12

22:34 aaa.txt

(3) 切換到第二個使用者shuihuo379,嘗試刪除zhangming使用者建立的檔案aaa.txt,此時提示無法刪除

[zhangming@localhost tmp]$ su

shuihuo379

[shuihuo379@localhost tmp]$

ls -l test/aaa.txt

-rw-rw-r--. 1 zhangming zhangming 6 oct 12

22:34 test/aaa.txt

[shuihuo379@localhost tmp]$

rm test/aaa.txt

rm: remove write-protected regular file `test/aaa.txt'

? yrm: cannot remove `test/aaa.txt'

: operation not permitted

(4) 重新切換到root使用者,執行刪除許可權位t操作

[shuihuo379@localhost tmp]$ su

[root@localhost tmp]#

chmod -t test

[root@localhost tmp]#

ls -ld

test

drwxrwxrwx.

2 root root 4096 oct 12

22:33 test

(5) 再次切換到使用者shuihuo379,嘗試刪除zhangming使用者建立的檔案aaa.txt,此時刪除成功,zhangming使用者建立的檔案aaa.txt已經不存在了

[root@localhost tmp]# su

shuihuo379

[shuihuo379@localhost tmp]$

ls -l test

total

4-rw-rw-r--. 1 zhangming zhangming 6 oct 12

22:34

aaa.txt

[shuihuo379@localhost tmp]$

rm test/aaa.txt

rm: remove write-protected regular file `test/aaa.txt'

? y[shuihuo379@localhost tmp]$ ls -l test

total

0

===

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 許可權進行講解。首先需要明...

Linux下檔案許可權的設定

檔案 目錄許可權設定命令 chmod 這是linux系統管理員最常用到的命令之一,它用於改變檔案或目錄的訪問許可權。該命令有兩種用法 用包含字母和操作符表示式的文字設定法 其語法格式為 chmod who opt mode 檔案 目錄名 其中who表示物件,是以下字母中的乙個或組合 u 表示檔案所有...