1.查看acl命令
getfacl 文件名 #查看acl權限
2.設定acl權限命令
setfacl 選項 文件名 選項: -m 設置ACL權限 -x 刪除指定的ACL權限 -b 刪除所有的ACL設定權限 -R 遞歸設置ACL權限 -d 設置默認的ACL權限(只對目錄有效,在該目錄新建的文件也會使用此 ACL默認值) -k 刪除默認的ACL權限
2.1添加用戶acl權限
[root@localhost ~]# mkdir /test #創建test目錄 [root@localhost ~]# ll -d /test #查看test目錄文件詳細信息 drwxr-xr-x. 2 root root 6 4月 16 09:37 /test [root@localhost ~]# useradd test1 #創建test1用戶 [root@localhost ~]# useradd test2 #創建test2用戶 [root@localhost ~]# groupadd testgroup #創建testgroup組 [root@localhost ~]# gpasswd -a test1 testgroup #將test1用戶添加到testgroup組 正在將用戶“test1”加入到“testgroup”組中 [root@localhost ~]# gpasswd -a test2 testgroup #將test2添加到testgroup組 正在將用戶“test2”加入到“testgroup”組中 [root@localhost ~]# cat /etc/group #查看group文件testgroup組用戶
[root@localhost ~]# chown root:testgroup /test #修改test目錄身份
[root@localhost ~]# chmod 770 /test #修改test目錄權限
[root@localhost ~]# ll -d /test#查看test詳細信息
drwxrwx---. 2 root testgroup 6 4月 16 09:37 /test
[root@localhost ~]# useradd test #添加一個額外的用戶,對test目錄不同的權限操作
[root@localhost ~]# passwd test #添加用戶密碼
更改用戶 test 的密碼 。
新的 密碼:
無效的密碼: 密碼少於 8 個字符
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
[root@localhost ~]# setfacl -m u:test:rx /test #設置test文件acl全權限
[root@localhost ~]# ll -d /test
drwxrwx---+ 2 root testgroup 6 4月 16 09:37 /test #test目錄權限多了個加號,說明有acl權限了
[root@localhost ~]# getfacl /test #查看目錄acl具體信息
getfacl: Removing leading '/' from absolute path names
# file: test
# owner: root
# group: testgroup
user::rwx
user:test:r-x #test用戶擁有了test目錄讀和執行權限
group::rwx
mask::rwx
other::---
[root@localhost ~]# su test #切換test用戶
[test@localhost root]$ cd /test #test用戶可以進入
[test@localhost test]$ touch a #test用戶不能創建
touch: 無法創建"a": 權限不夠
2.2添加組acl權限
[root@localhost test]# groupadd testgroup1 #添加testgroup1組 [root@localhost test]# setfacl -m g:testgroup1:rwx /test #設置test目錄acl testgroup組權限 [root@localhost test]# getfacl /test #查看test目錄acl權限 getfacl: Removing leading '/' from absolute path names # file: test # owner: root # group: testgroup user::rwx user:test:r-x group::rwx group:testgroup1:rwx #test目錄擁有了testgroup1組額外rwx權限 mask::rwx other::---
3.設置最大有效權限
在設置完acl時,查看都能看到倒數第二行有個mask項,這個mask是對acl權限的一個限定的。也就是說acl的設定權限不一定是真正的有效權限,
是需要和mask相與“”才是真的有效權限。
來個例子:
[root@localhost ~]# setfacl -m m:rw /test #給test目錄設置最大有效權限 [root@localhost ~]# getfacl /test #查看test目錄acl權限 getfacl: Removing leading '/' from absolute path names # file: test # owner: root # group: testgroup user::rwx user:test:r-x #effective:r-- #test用戶acl有效權限是r-- group::rwx #effective:rw- #所屬組有效權限是rw- group:testgroup1:rwx #effective:rw- #testgroup1有效acl權限rw- mask::rw- other::---
mask權限的設定不影響所有者的權限。默認不寫的話,mask權限是rwx
4.刪除ACL權限
刪除acl權限命令:
setfacl -x 用戶或組 文件名
[root@localhost ~]# setfacl -x g:testgroup1 /tes#刪除testgroup1的acl權限 [root@localhost ~]# getfacl /test #查看test目錄acl權限 getfacl: Removing leading '/' from absolute path names # file: test # owner: root # group: testgroup user::rwx user:test:r-x group::rwx mask::rwx other::---
testgroup1組的acl權限已經沒了。
也可以一次性刪除目錄下所有acl權限
setfacl -d 文件名
[root@localhost ~]# setfacl -b /test #刪除test目錄所有acl權限 [root@localhost ~]# getfacl /test getfacl: Removing leading '/' from absolute path names # file: test # owner: root # group: testgroup user::rwx group::rwx other::---
5.遞歸ACL權限
有時候希望目錄下面子文件或子文件夾使用父目錄的acl權限,而不是每次都手動設置acl命令。遞歸ACL就是完成這個操作
命令:
setfacl -R 文件名 #該命令只能針對目錄及子目錄操作
[root@localhost ~]# setfacl -m u:test:rw /test #先不用遞歸設置test目錄acl權限
[root@localhost ~]# getfacl /test
getfacl: Removing leading '/' from absolute path names
# file: test
# owner: root
# group: testgroup
user::rwx
user:test:rw-
group::rwx
mask::rwx
other::---
[root@localhost ~]# cd /test #test目錄下創建的a,b文件為沒有acl權限的 [root@localhost test]# touch a [root@localhost test]# touch b [root@localhost test]# ll 總用量 0 -rw-r--r--. 1 root root 0 4月 16 13:51 a -rw-r--r--. 1 root root 0 4月 16 13:51 b [root@localhost test]# setfacl -m u:test:rw -R /test #使用遞歸設置test目錄acl權限 [root@localhost test]# getfacl /test getfacl: Removing leading '/' from absolute path names # file: test # owner: root # group: testgroup user::rwx user:test:rw- group::rwx mask::rwx other::--- [root@localhost test]# ll 總用量 0 -rw-rw-r--+ 1 root root 0 4月 16 13:51 a #a文件已經有acl權限了 -rw-rw-r--+ 1 root root 0 4月 16 13:51 b
注意一點:遞歸設置acl文件只能對現有的文件實現,后面新建的文件是沒有acl權限的。如果你想后面新建文件也能實現acl權限,就是后面的默認acl權限了
6.默認ACL權限
命令:
setfacl -m d: u:用戶名:權限 文件名 #該命令只能目錄有效
[root@localhost test]# setfacl -m d:u:test:rw -R /test [root@localhost test]# touch c [root@localhost test]# ll 總用量 0 -rw-rw-r--+ 1 root root 0 4月 16 13:51 a -rw-rw-r--+ 1 root root 0 4月 16 13:51 b -rw-rw----+ 1 root root 0 4月 16 14:11 c #后面c文件也有了acl權限
2019-04-16