Linux下的許可權

2021-07-27 13:48:59 字數 3075 閱讀 2690

linux系統內有檔案有三種身份 u:擁有者  g:群組   o:其他人

這些身份對於文件又有下面許可權 可以用ls -l 檔名 檢視許可權資訊

r:讀許可權,使用者可以讀取文件的內容,如用cat,more檢視

w:寫許可權,使用者可以編輯文件

x:該目錄具有可以被系統執行的許可權

s root執行

s許可權是'使用root使用者執行'的許可權。在這裡使用 chmod +s filename 和 chmod -s filename 來更改檔案的s許可權。檔案的s許可權位區分大小寫,如果是大寫的s就是s位沒有生效,如果是小寫的s就是s位已經生效。如果使用者本身沒有檔案的x許可權,就直接加上了s許可權就會導致s許可權位失效,顯示為大寫s。s許可權只能使用在二進位制檔案上。

linux下的 passwd 命令是任何人都可以用的,最起碼可以用來修改自己的密碼。但是我們的密碼又是存在 /etc/shdown 裡的,如果我們修改了自己的密碼那麼必要要修改這個檔案。然而這個檔案的許可權是 ----------. 也就是任何人都不能修改。那麼 passwd 這個命令就可以讓普通使用者臨時提公升許可權,從而修改這個檔案,所以 passwd 這個命令檔案的許可權就包含了s許可權。

[root@localhost ~]# ls -l /etc/shadow

----------. 1 root root 2104 sep 29 12:37 /etc/shadow

[root@localhost ~]# ls -l /usr/bin/passwd

-rwsr-xr-x. 1 root root 27832 jun 10  2014 /usr/bin/passwd

t 禁止刪除

t許可權是『不可刪除』許可權,就是說即使某使用者擁有這個檔案的rwx許可權,可以隨意修改檔案內容,但是就是不能刪除,甚至不能修改檔名,只有root才行。t許可權也可以直接用 chmod +t 

filename 和 chmod -t filename 來修改。

[testusert@localhost shell]$ chmod +t test_t.py

[testusert@localhost shell]$ ls -l

total 16

-rw-r--r--. 1 root      root      67 sep 29 12:22 test_a.py

-rw-r--r--. 1 root      root      55 sep 29 11:42 test_i.py

-rw-r--r--. 1 root      root      55 sep 29 12:19 test_s.py

-rw-r--r-t. 1 testusert testusert 61 sep 29 12:34 test_t.py

[testusert@localhost shell]$ echo "hello,world" > test_t.py

[testusert@localhost shell]$ echo "hello,world" >> test_t.py

[testusert@localhost shell]$ rm test_t.py

rm: cannot remove 『test_t.py』: permission denied

[testusert@localhost shell]$ mv test_t.py test_tt.py

mv: cannot move 『test_t.py』 to 『test_tt.py』: permission denied

a 只追加

a許可權是'只追加'許可權,可以給日誌類或者其他需要的檔案設定此許可權。設定了a許可權的檔案只能進行追加,且不能使用文字編輯器追加。可以使用 chattr +a filename 和 chattr -a filename 設定a許可權,使用 lsattr filename 檢視特殊許可權。

[root@localhost shell]# chattr +a test_a.py

[root@localhost shell]# lsattr test_a.py

-----a---------- test_a.py

[root@localhost shell]# echo "hello,world" > test_a.py  #不能將資料直接覆蓋

bash: test_a.py: operation not permitted

[root@localhost shell]# echo "hello,world" >> test_a.py #可以將資料追加到後面

如果我們試圖使用vim等文字編輯器去修改具有a許可權的檔案的話,在儲存的時候就會提示沒有相應的許可權 e212: cannot open file for writing ,我這裡是vim給出的警告。

i 不可修改

i許可權是乙個完全不可修改的許可權,即使這個檔案許可權是777也必須要取消掉i許可權才可以修改。我們還是使用 lsattr filename 檢視i許可權設定,然後使用 chattr +i filename 和 chattr -i 

filename 設定a許可權。

[root@localhost shell]# lsattr test_i.py

---------------- test_i.py

[root@localhost shell]# chattr +i test_i.py

[root@localhost shell]# lsattr test_i.py

----i----------- test_i.py

#刪除,覆蓋,追加都不行

[root@localhost shell]# echo "hello,world" > test_i.py

bash: test_i.py: permission denied

[root@localhost shell]# echo "hello,world" >> test_i.py

bash: test_i.py: permission denied

[root@localhost shell]# rm test_i.py

rm: remove regular file 『test_i.py』? y

rm: cannot remove 『test_i.py』: operation not permitted

linux下的許可權

1 檔案訪問者的分類 人 a 檔案和 檔案目錄的所有者 u user b 檔案和 檔案 目錄的所有者所在的組的 使用者 g group c 其它 使用者 o others 2 檔案訪問許可權的種類 事物屬性 a 讀 r 4 read對 檔案 而 言,具有讀取 檔案內容的許可權 對 目錄來說,具有瀏覽...

linux下的許可權

linux 下的許可權有 讀 寫 執行讀 r寫 w執行 x用ll可以看到任意乙個檔案 ll後第乙個字母為d稱為目錄檔案,第乙個為 稱為普通檔案 的許可權情況 1.任何乙個檔案針對不同的使用者許可權是不一樣的 2.與許可權有關的命令 chmod r 檔案 去掉檔案的讀許可權 chmod r 檔案 加上...

linux下的檔案許可權

假設有兩個使用者usera,userb,其中usera對path擁有rwx 許可權,而path test.txt屬於userb,那麼請問usera是否可以對path test.txt進行操作?答案 usera可以刪除test.txt因為它具有path的執行許可權,這個許可權包括了刪除。那麼usera...