ACL許可權控制
設定ACL許可權:setfacl
查看ACL許可權:getfacl
ACL許可權控制主要目的是提供傳統的owner,group,other的read,wirte,execute許可權之外的具體使用權限設定,可以針對單一使用者或組來設定特定的許可權
比如:某一目錄許可權為
drwx------ 2 root root 4096 03-10 13:51./acldir
使用者user對此目錄無任何許可權因此無法進入此目錄,ACL可單獨為使用者user設定這個目錄的許可權,使其可以操作這個目錄
ACL啟動
要使用ACL必須要有檔案系統支援才行,目前絕大多數的檔案系統都會支援,EXT3檔案系統預設啟動ACL的
查看檔案系統是否支援ACL
[root@localhost tmp]#
dumpe2fs -h /dev/sda2 dumpe2fs 1.39 (29-May-2006)
……
sparse_super large_file
Default mount options: user_xattr acl
載入ACL功能
如果UNIX LIKE支援ACL但是檔案系統並不是預設載入此功能,可自己進行添加
[root@localhost tmp]# mount -o remount,acl /
[root@localhost tmp]# mount
/dev/sda2 on / type ext3 (rw,acl)
同樣也可以修改磁碟掛在設定檔設定預設開機載入
[root@localhost tmp]# vi /etc/fstab
LABEL=/ / ext3 defaults,acl 1 1
查看ACL許可權
文法:getfacl filename
設定ACL許可權
文法:setfacl [-bkRd] [-m|-x acl 參數] 目標檔案名
選項與參數:
-m:設定後續的acl參數,不可與-x一起使用
-x: 刪除後續的acl參數,不可與-m一起使用
-b:刪除所有的acl參數
-k:刪除預設的acl參數
-R:遞迴設定acl參數
-d:設定預設acl參數,只對目錄有效
針對特殊使用者
設定格式:u:使用者帳號列表:許可權
許可權:rwx的組合形式
如使用者列表為空白,代表設定當前檔案所有者許可權
舉例:
[root@localhost tmp]# mkdir -m 700 ./acldir; ll -d ./acldir
drwx------ 2 root root 4096 03-10 13:51 ./acldir
[root@localhost tmp]# su tkf
[tkf@localhost tmp]$ cd ./acldir/
bash: cd: ./acldir/: 許可權不夠 =>使用者無X許可權
[tkf@localhost tmp]$ exit
exit
[root@localhost tmp]# setfacl -m u:tkf:x ./acldir/
=>針對使用者tkf設定acldir目錄的許可權為x
[root@localhost tmp]# ll -d ./acldir/
drwx--x---+ 2 root root 4096 03-10 13:51 ./acldir/
=>通過ACL添加許可權在許可權末尾會增加多個一個“+”同時檔案原本許可權也發生變化。
=>可通過getfacl查看原始目錄許可權
[root@localhost tmp]# getfacl ./acldir/
# file: acldir
# owner: root
# group: root
user::rwx
user:tkf:--x =>記錄tkf使用者針對此目錄有acl許可權
group::---
mask::--x
other::---
=>這裡需要特殊說明,只是tkf這個使用者具有X許可權,其他使用者還是無許可權的
[root@localhost tmp]# su tkf
[tkf@localhost tmp]$ cd ./acldir/
[tkf@localhost acldir]$
=>使用者tkf可以具有x許可權可以進入目錄
針對特定使用者組
設定格式:g:使用者組列表:許可權
許可權:rwx的組合形式
如使用者組列表為空白,代表設定當前檔案所屬使用者組許可權
舉例:
[root@localhost tmp]# setfa
setfacl setfattr
[root@localhost tmp]# setfacl -m g:users:rx ./acldir/
[root@localhost tmp]# getfacl ./acldir/
# file: acldir
# owner: root
# group: root
user::rwx
user:tkf:--x
group::--- => 其他使用者組(非acl設定)的許可權
group:users:r-x => 記錄users使用者組針對此目錄有acl許可權
mask::r-x
other::---
針對有效使用權限設定
有效許可權(mask)就是acl使用權限設定的極限值,也就是你所設定的acl許可權一定是mask的一個子集,如果超出mask範圍會將超出的許可權去掉
設定格式:m:許可權
許可權:rwx的組合形式
舉例:
[root@localhost tmp]# setfacl -m m:x ./acldir/
[root@localhost tmp]# getfacl ./acldir/
# file: acldir
# owner: root
# group: root
user::rwx
user:tkf:--x
group::r-x #effective:--x
group:users:r-x #effective:--x
mask::--x
other::---
針對預設使用權限設定
我們前面都是針對一個目錄為一個使用者(組)設定特定許可權,但是如果這個目錄下在新建立的檔案是不具有這些針對這個使用者的特定許可權的。為瞭解決這個問題,就需要設定預設acl許可權,使這個目錄下新建立的檔案有和目錄相同的ACL特定許可權
設定格式:d:[u|g]:使用者(組)列表:許可權
舉例
[root@localhost tmp]# mkdir -m 711 ./defdir
[root@localhost tmp]# setfacl -m u:tkf:rxw ./defdir
[root@localhost tmp]# ll -d ./defdir/
drwxrwx--x+ 2 root root 4096 03-10 15:23 ./defdir/
=>目錄許可權具有acl特定許可權(後面+)
[root@localhost tmp]# touch ./defdir/a.file;ll ./defdir/
-rw-r--r-- 1 root root 0 03-10 15:25 a.file
=>新建立的檔案不具有acl特定許可權(後面無+)
[root@localhost tmp]# setfacl -m d:u:tkf:rxw ./defdir
=>設定預設許可權
[root@localhost tmp]
# getfacl ./defdir/
# file: defdir
# owner: root
# group: root
user::rwx
user:tkf:rwx
group::--x
mask::rwx
other::--x
default:user::rwx
default:user:tkf:rwx
default:group::--x
default:mask::rwx
default:other::--x
[root@localhost tmp]# touch ./defdir/b.file;ll ./defdir/
-rw-r--r-- 1 root root 0 03-10 15:25 a.file
-rw-rw----+ 1 root root 0 03-10 15:26 b.file
=>新建立檔案預設帶有acl特定許可權
[root@localhost tmp]
# getfacl ./defdir/b.file
# file: defdir/b.file
# owner: root
# group: root
user::rw- user:tkf:rwx #effective:rw-
group::--x #effective:---
mask::rw-
other::---
=>這快我有個疑問,為什麼mask值是rw,我猜測和檔案最大許可權有關,
=>對於檔案來時預設最大許可權是666即UMASK為0000.那個對於可執行檔來說
=>沒有X,難道還需要使用chmod設定? 疑問!!