linux檔案許可權(r、w、x、s、t、i、a)詳解

來源:互聯網
上載者:User

wx不必詳述。重點是s、t、i、a許可權

s:檔案屬主和組設定SUID和GUID,檔案在被設定了s許可權後將以root身份執行。在設定s許可權時檔案屬主、屬組必須先設定相應的x許可權,否 則s許可權並不能正真生效(c h m o d命令不進行必要的完整性檢查,即使不設定x許可權就設定s許可權,chmod也不會報錯,當我們ls -l時看到rwS,大寫S說明s許可權未生效)。Linux修改密碼的passwd便是個設定了SUID的程式,普通使用者無讀寫/etc/shadow檔案 的許可權確可以修改自己的密碼。

ls -al /usr/bin/passwd

-rw s r-xr-x 1 root root 32988 2008-12-08 17:17 /usr/bin/passwd

我們可以通過字元模式設定s許可權:chmod a+s filename,也可以使用絕對模式進行設定:

設定s u i d:將相應的許可權位之前的那一位設定為4;
設定g u i d:將相應的許可權位之前的那一位設定為2;
兩者都置位:將相應的許可權位之前的那一位設定為4+2=6。

如:

chmod 4 764 filename   //設定SUID
 
t :設定粘著位,一個檔案可讀寫的使用者並一定相讓他有刪除此檔案的許可權,如果檔案設定了t許可權則只用屬主和root有刪除檔案的許可權,通過chmod +t filename 來設定t許可權。
 
i:不可修改許可權  例:chattr u+i filename 則filename檔案就不可修改,無論任何人,如果需要修改需要先刪除i許可權,用chattr -i filename就可以了。查看檔案是否設定了i許可權用lsattr filename。
 
a:只追加許可權, 對於日誌系統很好用,這個許可權讓目標檔案只能追加,不能刪除,而且不能通過編輯器追加。可以使用chattr +a設定追加許可權

以root的身份登入Linux之後,在命令列中輸入『 ls -al 』後可以看到:

[root@www ~]# ls -al
total 156
drwxr-x--- 4 root root 4096 Sep 8 14:06 .
drwxr-xr-x 23 root root 4096 Sep 8 14:21 ..
-rw------- 1 root root 1474 Sep 4 18:27 anaconda-ks.cfg
-rw------- 1 root root 199 Sep 8 17:14 .bash_history
-rw-r--r-- 1 root root 24 Jan 6 2007 .bash_logout
-rw-r--r-- 1 root root 191 Jan 6 2007 .bash_profile
-rw-r--r-- 1 root root 176 Jan 6 2007 .bashrc
-rw-r--r-- 1 root root 100 Jan 6 2007 .cshrc
drwx------ 3 root root 4096 Sep 5 10:37 .gconf <=範例說明處
drwx------ 2 root root 4096 Sep 5 14:09 .gconfd
-rw-r--r-- 1 root root 42304 Sep 4 18:26 install.log <=範例說明處
-rw-r--r-- 1 root root 5661 Sep 4 18:25 install.log.syslog
[ 1 ][ 2 ][ 3 ][ 4 ][ 5 ][ 6 ] [ 7 ]

[ 許可權 ] [連結][擁有者] [群組] [檔案容量] [ 修改日期 ] [ ?n名 ]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.