ACL是Access Control List的縮寫,主要的目的是提供傳統的owner、group、others的read、write、execute權限之外的具體權限設置。ACL可以針對單一用戶、單一文件、單一目錄來進行r、w、x的權限設置,對于需要特殊權限的使用狀況非常有幫助。使用getfacl和setfacl來設置查看acl的權限。ACL權限給了x,文件也不會繼承x權限。ACL上的mask只是一種限制權限的機制影響除所有者和other的之外的人和組的最大權限。mask需要與用戶的權限進行邏輯與運算后,才能變成有限的權限(Effective Permission),用戶或組的設置必須存在于mask權限設定范圍內才會生效。它也不會給文件x權限。
setfacl 設置acl屬性
語法
setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file …
常用選項
-m #設置后續的acl參數給文件使用,不可與-x合用 -M #用文件或標準輸入來讀取acl的規則 -x #刪除后續的acl參數,不可與-m合用 -X #用文件或標準輸入來讀取acl的規則 -b #刪除所有的acl設置參數 -k #刪除默認的acl參數 -R #遞歸設置acl
例如
[root@localhost testdir]# ls #列出文件 sun [root@localhost testdir]# cat sun #查看文件,其他只有r權限 sssaaaaaaaaaaaaaa [root@localhost testdir]# setfacl -m u:tom:rw sun #設置acl權限 [root@localhost testdir]# getfacl sun #查看acl權限 # file: sun #文件名 "#"表示默認代表默認屬性 # owner: root #屬主 # group: root#屬組 user::rw- #文件所有者的權限 user:tom:rw- #自己設置的用戶權限 group::r--#用戶組的默認權限 mask::rw- #文件默認權限 other::r-- #其他人擁有的權限 [root@localhost testdir]# ll total 4 -rw-rw-r--+ 1 root root 42 Aug 6 18:39 sun #設置acl后面會有個"+"號 [root@localhost testdir]# su tom #切換其他用戶 [tom@localhost testdir]$ echo "newfile i am very tired" >>sun #寫入數據。(按理不用改有次權限) [tom@localhost testdir]$ cat sun #由于設置了acl,所有有了rw權限。 sssaaaaaaaaaaaaaa newfile i am very tired
mask就是一個界限,只能在它指定的范圍內的權限才可以。
[root@localhost testdir]# setfacl -m mask:r sun #設置mask默認為r [root@localhost testdir]# getfacl sun #查看acl表 # file: sun # owner: root # group: root user::rw- user:tom:rw-#effective:r-- #有效值 group::r-- mask::r-- other::r--
[root@localhost testdir]# getfacl -R file > acl.txt #備份訪問控制列表到acl.txt文件中 [root@localhost testdir]# ll total 12 -rw-r--r-- 1 root root 115 Aug 6 19:03 acl.txt -rw-rw-r--+ 1 root root 5 Aug 6 17:55 file -rw-r--r-- 1 root root 45 Aug 6 17:44 file1 [root@localhost testdir]# cat acl.txt #備份的acl條目 # file: file # owner: root # group: root user::rw- group::r-- group:Cloud:rwx#effective:rw- mask::rw- other::r--
[root@localhost testdir]# setfacl -b file #清空acl [root@localhost testdir]# ll total 12 -rw-r--r-- 1 root root 115 Aug 6 19:03 acl.txt -rw-r--r-- 1 root root 5 Aug 6 17:55 file -rw-r--r-- 1 root root 45 Aug 6 17:44 file1 [root@localhost testdir]# setfacl -R --set-file=acl.txt file #恢復acl [root@localhost testdir]# ll total 12 -rw-r--r-- 1 root root 115 Aug 6 19:03 acl.txt -rw-rw-r--+ 1 root root 5 Aug 6 17:55 file -rw-r--r-- 1 root root 45 Aug 6
原創文章,作者:ladsdm,如若轉載,請注明出處:http://www.www58058.com/30122