用到程式:
chmod setfacl getfacl stat chattr lsattr
chmod:設定檔案許可權
setfacl:設定存取控制清單(access control list)
getfacl:查看存取控制清單
stat:顯示inode內容(a|m|c)time內容
chattr:設定第二擴充檔案的列表檔案屬性系統
lsattr:查看第二擴充檔案的列表檔案屬性系統
setuid:使檔案擁有和檔案屬主相同的x許可權
setgid:使檔案夾擁有和檔案屬組相同的x許可權
sticky:使檔案不可冊除
Test:
[root@nagios test]# touch setuid setgid sticky [root@nagios test]# chown -R nagios.nagios ./ [root@nagios test]# chmod u+s setuid && chmod g+s setgid && chmod o+t sticky [root@nagios test]# ll total 0-rw-r-Sr-- 1 nagios nagios 0 Mar 28 00:41 setgid -rwSr--r-- 1 nagios nagios 0 Mar 28 00:41 setuid -rw-r--r-T 1 nagios nagios 0 Mar 28 00:41 sticky [root@nagios test]# su hello [hello@nagios test]$ pwd /root/test [hello@nagios test]$ echo hello >> setuid bash: setuid: Permission denied [hello@nagios test]$ sh setuid hello [nagios@nagios test]$ exit exit [root@nagios test]# chmod o+w sticky [root@nagios test]# su hello [hello@nagios test]$ ll sticky -rw-rw-rwT 1 nagios nagios 0 Mar 28 00:45 sticky [hello@nagios test]$ rm sticky rm: cannot remove `sticky': Permission denied [hello@nagios test]$ stat sticky File: `sticky' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 134198 Links: 1Access: (1666/-rw-rw-rwT) Uid: ( 500/ nagios) Gid: ( 500/ nagios) Access: 2013-03-28 00:45:37.875928997 +0800Modify: 2013-03-28 00:45:37.875928997 +0800Change: 2013-03-28 00:46:28.050580800 +0800
#setfacl and getfacl
user:: user: 屬主許可權 "::"均為屬主 ":" 為特殊使用者
group:: group: 組和特殊組
other:: 其它人
mask:: 除了屬主和其他人之外的所有人
常用選項:
-d : 子目錄繼承父目錄的特殊許可權。
-R : 遞迴許可權
查看是否支援ACL
[root@nagios heelo]# tune2fs -l /dev/sda1 | grep option Default mount options: user_xattr acl
test:
[root@nagios test]# touch setfacl [root@nagios test]# setfacl -m user::r,user:hello:rw setfacl [root@nagios test]# chown nagios.nagios setfacl [root@nagios test]# ll setfacl -r--rw-r--+ 1 nagios nagios 0 Mar 28 00:52 setfacl [root@nagios test]# su nagios [nagios@nagios test]$ echo hello >> setfacl bash: setfacl: Permission denied [nagios@nagios test]$ exit exit [root@nagios test]# su hello [hello@nagios test]$ echo hello >> setfacl [hello@nagios test]$ cat setfacl hello [hello@nagios test]$ getfacl setfacl # file: setfacl # owner: nagios # group: nagios user::r-- user:hello:rw- group::r-- mask::rw- other::r--
#chattr and lsattr
Chattr +-=[acdeijstuADST].
A:Atime,告訴系統不要修改對這個檔案的最後訪問時間。
S:Sync,一旦應用程式對這個檔案執行了寫操作,使系統立刻把修改的結果寫到磁碟。
a:Append Only,系統只允許在這個檔案之後追加資料,不允許任何進程覆蓋或截斷這個檔案。如果目錄具有這個屬性,系統將只允許在這個目錄下建立和修改檔案,而不允許刪除任何檔案。
i:Immutable,系統不允許對這個檔案進行任何的修改。如果目錄具有這個屬性,那麼任何的進程只能修改目錄之下的檔案,不允許建立和刪除檔案。
D:檢查壓縮檔中的錯誤。
d:No dump,在進行檔案系統備份時,dump程式將忽略這個檔案。
C:Compress,系統以透明的方式壓縮這個檔案。從這個檔案讀取時,返回的是解壓之後的資料;而向這個檔案中寫入資料時,資料首先被壓縮之後才寫入磁碟。
s:Secure Delete,讓系統在刪除這個檔案時,使用0填充檔案所在的地區。
u:Undelete,當一個應用程式請求刪除這個檔案,系統會保留其資料區塊以便以後能夠恢複刪除這個檔案。
test:
[root@nagios test]# mkdir chattr [root@nagios test]# chattr +i chattr/ [root@nagios test]# touch chattr/hello touch: cannot touch `chattr/hello': Permission denied [root@nagios test]# chattr -i +a chattr/ [root@nagios test]# touch chattr/hello && echo hello >>chattr/hello && cat chattr/hello hello [root@nagios test]# rm chattr/hello rm: remove regular file `chattr/hello'? y rm: cannot remove `chattr/hello': Operation not permitted