Linux檔案ACL通路控制政策
- 檢視檔案是否有ACL政策
- 設定ACL政策(setacl)
- 修改或設定ACL政策setfacl -m
- 給指定使用者單獨加ACL政策setfacl -m u:
- 給指定組單獨加ACL政策setfacl -m g:
- mask:定義除其他人和所有者外的最大權限setfacl -m m::
- 遞歸授權-R
- 删除ACL政策setacl -x
- 删除指定使用者的ACL政策setfacl -x u:
- 删除指定組的ACL政策setfacl -x g:
- 删除mask的ACL政策setfacl -x m:
- 删除檔案所有ACL政策setfacl -b
- 預設ACL政策setacl -d
- 檢視檔案的ACL政策getfacl
參考連結:
linux-通路控制清單.html
ACL的出現,則是為了擴充Linux的檔案權限控制,以實作更為複雜的權限控制需求。其可以針對任意的使用者和使用者組進行權限配置設定(隻有root使用者可以定義ACL),以及預設權限配置設定。
## 如果左側的權限欄中有 + 号,就是ACL權限
[root@localhost ~]# ll new.sh
-rwxrwxr-x+ 1 root root 1500 8月 14 18:18 new.sh
# 修改或設定ACL政策
setfacl -m
setfacl -m u:user1:rwx new.sh
setfacl -m g:user1:rwx new.sh
除其他人和所有者外—指的就是使用者組
mask權限和屬組權限沖突時,以mask權限為準
# 設定mask權限
[root@localhost ~]# setfacl -m m::r new.sh
# 檢視new.sh的acl政策
## 雖然group依然鱻是的r-x,但實際上隻有r權限了
[root@localhost ~]# getfacl new.sh
# file: new.sh
# owner: root
# group: root
user::rwx
group::r-x #effective:r--
mask::r--
other::r-x
-R 遞歸授權,對目錄下已存在的目錄或檔案設定acl政策,但新的檔案不設定ACL政策
## setfacl -Rm u:使用者名:權限 目錄名
setfacl -Rm u:user1:rwx dir1
## 進入dir
cd dir1
## 檢視檔案權限
[root@localhost dir1]# ls -la
總用量 4
drwxrwxr-x+ 2 root root 137 9月 5 22:05 .
dr-xr-x---. 9 root root 4096 9月 5 22:04 ..
-rw-rwxr--+ 1 root root 0 9月 5 22:05 test1
-rw-rwxr--+ 1 root root 0 9月 5 22:05 test10
## 檢視目錄下檔案的ACL政策
[root@localhost dir1]# getfacl *
# file: test1
# owner: root
# group: root
user::rw-
user:user1:rwx
group::r--
mask::rwx
other::r--
# file: test10
# owner: root
# group: root
user::rw-
user:user1:rwx
group::r--
mask::rwx
other::r--
setacl -x
# 删除user1在new.sh檔案中的ACL政策
setfacl -x u:user1 new.sh
## 檢視該檔案删除政策後的ACL政策
[root@localhost ~]# getfacl new.sh
# file: new.sh
# owner: root
# group: root
user::rwx
group::r-x
group:user1:rwx
mask::rwx
other::r-x
# 删除user1組在new.sh檔案中的ACL政策
setfacl -x g:user1 new.sh
## 檢視該檔案删除政策後的ACL政策
[root@localhost ~]# getfacl new.sh
# file: new.sh
# owner: root
# group: root
user::rwx
group::r-x
mask::r-x
other::r-x
# 删除mask的ACL政策
setfacl -x m: new.sh
## 檢視該檔案删除政策後的ACL政策
[root@localhost ~]# getfacl new.sh
# file: new.sh
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
# 删除檔案的所有ACL政策
setfacl -b new.sh
## 檢視該檔案删除政策後的ACL政策
[root@localhost ~]# getfacl new.sh
# file: new.sh
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
-d 隻針對目錄,該目錄下建立的目錄和檔案都會繼承ACL政策,老的檔案不會改變現有的ACL政策,與-R遞歸授權正好相反。
# 建立一個新目錄dir2
[root@localhost ~]# mkdir dir2
[root@localhost ~]# cd dir2
# 在新目錄中建立一個老檔案test1
[root@localhost dir2]# touch test1
[root@localhost dir2]# cd ..
# 為dir2目錄設定預設ACL政策
[root@localhost ~]# setfacl -dm u:user1:rwx dir2
# 設定ACL政策後再建立一個新檔案
[root@localhost ~]# touch dir2/test2
# 對比檢視新檔案和老檔案的ACL政策
## 隻有新檔案有ACL政策,老檔案沒有
[root@localhost ~]# getfacl dir2/*
# file: dir2/test1
# owner: root
# group: root
user::rw-
group::r--
other::r--
# file: dir2/test2
# owner: root
# group: root
user::rw-
user:user1:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--
[root@localhost ~]# getfacl new.sh
# file: new.sh
# owner: root
# group: root
user::rwx
user:user1:rwx
group::r-x
group:user1:rwx
mask::rwx # mask是除了擁有者及其他人(other)以外的人擁有的權限
other::r-x