天天看點

Linux中ACl權限- getfacl, setfacl

ACL 是 Access Control List 的縮寫,主要的目的是在提供傳統的 owner,group,others 的 read,write,execute 權限之外的細部權限設定。

ACL 可以針對單一使用者,單一檔案或目錄來進行 r,w,x 的權限規範,對于需要特殊權限的使用狀況非常有幫助。

setfacl 指令用法

[[email protected] ~]# setfacl [-bkRd] [{-m|-x} acl參數]目标檔名
選項與參數:
-m :設定後續的acl 參數給檔案使用,不可與-x 合用;  # mask:有效權限
-x :删除後續的acl 參數,不可與-m 合用;
-b :移除『所有的』 ACL 設定參數;
-k :移除『預設的』 ACL 參數,關于所謂的『預設』參數于後續範例中介紹;
-R :遞回設定acl ,亦即包括次目錄都會被設定起來;
-d :設定『預設acl 參數』的意思!隻對目錄有效,在該目錄建立的資料會引用此預設值  #為目錄添加預設的acl權限,此目錄下建立目錄和檔案都會繼承此權限資訊
           
  • 删除ACL使用者權限:setfacl -x u:使用者名 檔案名
  • 删除ACL組權限:setfacl -x g:組名 檔案名
  • 删除整個ACL權限:setfacl -b 檔案名
針對使用者的設定方式:『 u:使用者名:權限』

設定前請加上 -m 這個選項。一個檔案設定了ACL 參數後,他的權限部分就會多出一個 + 号

//設定user對testfile有rwx權限
setfacl -m u:user:rwx testfile 

//設定user對testdirectory目錄下所有檔案有RWX權限
setfacl -R -m u:user:rwx testdirectory 

//去掉user對testdirectory的x權限
setfacl -x u:user testdirectory/   

//去掉所有acl權限
setfacl -b 

//為testdirectory目錄添加預設的acl權限,此目錄下建立目錄和檔案,user都有rwx權限
setfacl -d -m u:user:rwx testdirectory/
           
針對群組的權限設定:『 g:群組名:權限』
#設定規範:『 g:[群組清單]:[rwx] 』,例如針對mygroup1的權限規範rx : 
[root@study ~]# setfacl -mg:mygroup1:rx acl_test1 
[root@study ~]# getfacl acl_test1
# file: acl_test1
# owner: root
# group: root
user::rwx
user:vbird1:rx
group::r--
group:mygroup1:rx   <==這裡就是新增的部分!多了這個群組的權限設定!
mask::rx
other::r--
           

getfacl 指令用法

getfacl:取得某個檔案/目錄的ACL 設定項目;

[root@study ~]# getfacl filename

列出剛剛我們設定的acl_test1的權限内容: 
[root@study ~]# getfacl acl_test1 
# file: acl_test1    <==說明檔名而已!
# owner: root        <==說明此檔案的擁有者,亦即ls -l看到的第三使用者欄位 
# group: root        <==此檔案的所屬群組,亦即ls -l看到的第四群組欄位 
user::rwx            <==使用者清單欄是空的,代表檔案擁有者的權限
user:vbird1:rx      <==針對vbird1的權限設定為rx ,與擁有者并不同!
group::r--           <==針對檔案群組的權限設定僅有r 
mask::rx            <==此檔案預設的有效權限(mask) 
other::r--           <==其他人擁有的權限啰!
           

常用指令

getfacl filename
setfacl -m u:user:rwx testfile 
setfacl -R -d -m u:user:rwx testdirectory 
           

繼續閱讀