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