ACL权限
目录
1、查看ACL命令
[root@localhost ~]# getfacl 文件名
#查看acl权限
[root@CentOS7 ~]# getfacl a
# file: a //文件名
# owner: root //所有者
# group: root //所属组
user::rw- //用户权限
group::r-- //组权限
other::r-- //其他人权限
2、设定ACL权限的命令
-
相关用法
[root@CentOS7 ~]# setfacl 选项 文件名
选项:
-m 设定ACL权限
-x 删除指定的ACL权限
-b 删除所有的ACL权限
-d 设定默认ACL权限.
-k 删除默认ACL权限
-R 递归设定ACL权限。
-
权限
//给用户设权限
[root@CentOS7 ~]# setfacl -m u:li4:rwx a
[root@CentOS7 ~]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx
group::r--
mask::rwx
other::r--
//给组设权限
[root@CentOS7 ~]# setfacl -m g:tg:rwx a
[root@CentOS7 ~]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx
group::r--
group:tg:rwx
mask::rwx
other::r--
//给其他人设权限
[root@CentOS7 ~]# setfacl -m o:rwx a
[root@CentOS7 ~]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx
group::r--
group:tg:rwx
mask::rwx
other::rwx
//可以看到权限位置有个+
[root@CentOS7 ~]# ls -l a
-rw-rwxrwx+ 1 root root 0 4月 13 21:50 a
-
默认权限
//给用户设置默认权限
[root@CentOS7 ~]# setfacl -m d:u:li4:rwx b
[root@CentOS7 ~]# getfacl b
# file: b
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:li4:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
//给组设置默认权限
[root@CentOS7 ~]# setfacl -m d:g:tg:rwx b
[root@CentOS7 ~]# getfacl b
# file: b
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:li4:rwx
default:group::r-x
default:group:tg:rwx
default:mask::rwx
default:other::r-x
//给其他人设置默认权限
[root@CentOS7 ~]# setfacl -m d:o:rwx b
[root@CentOS7 ~]# getfacl b
# file: b
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:li4:rwx
default:group::r-x
default:group:tg:rwx
default:mask::rwx
default:other::rwx
//可以看到权限位置有个+
[root@CentOS7 ~]# ls -ld b
drwxr-xr-x+ 2 root root 6 4月 13 22:07 b
[root@CentOS7 ~]# cd b
[root@CentOS7 b]# touch a
[root@CentOS7 b]#
[root@CentOS7 b]# ls -l a
-rw-rw-rw-+ 1 root root 0 4月 13 22:13 a
[root@CentOS7 b]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx #effective:rw- //这三个是默认权限与mask权限与出来的结果
group::r-x #effective:r-- //实际有效权限
group:tg:rwx #effective:rw-
mask::rw-
other::rw-
//默认ACL权限的作用是:如果给父目录设定了默认ACL权限,那么父目录中所有新建的子文件都会继承父目录的ACL权限。
-
递归权限
//设置递归用户权限
[root@CentOS7 ~]# setfacl -m u:li4:rwx -R c
[root@CentOS7 ~]# getfacl c
# file: c
# owner: root
# group: root
user::rwx
user:li4:rwx
group::r-x
mask::rwx
other::r-x
[root@CentOS7 c]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx
group::r--
mask::rwx
other::r--
//设置递归组权限
[root@CentOS7 ~]# setfacl -m g:tg:rwx -R c
[root@CentOS7 ~]# getfacl c
# file: c
# owner: root
# group: root
user::rwx
user:li4:rwx
group::r-x
group:tg:rwx
mask::rwx
other::r-x
[root@CentOS7 c]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx
group::r--
group:tg:rwx
mask::rwx
other::r--
//设置递归默认权限
[root@CentOS7 ~]# setfacl -m d:u:wang5:rwx -R c
[root@CentOS7 ~]# getfacl c
# file: c
# owner: root
# group: root
user::rwx
user:li4:rwx
group::r-x
group:tg:rwx
mask::rwx
other::r-x
default:user::rwx
default:user:wang5:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
[root@CentOS7 c]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:rwx
group::r--
group:tg:rwx
mask::rwx
other::r--
//这里可以看到递归默认无效,而下面的组有效(这里要注意命令执行的先后)
[root@CentOS7 ~]# setfacl -m d:u:wang5:rwx -R c
[root@CentOS7 c]# getfacl d
# file: d
# owner: root
# group: root
user::rwx
user:wang5:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:wang5:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
-
最大有效权限mask
mask是用来指定最大有效权限的。如果我给用户赋予了ACL权限,是需要和mask的权限“相与”才能得到用户的真正权限
[root@CentOS7 ~]# setfacl -m m:rwx f
[root@CentOS7 ~]# getfacl f
# file: f
# owner: root
# group: root
user::rwx
group::r-x
mask::rwx
other::r-x
[root@CentOS7 f]# setfacl -m u:li4:r a
[root@CentOS7 f]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:li4:r-- //可以看到就一个r权限
group::r--
mask::r--
other::r--
-
删除ACL权限
[root@CentOS7 ~]# setfacl -x u:用户名 文件名
#删除指定用户的ACL权限
[root@CentOS7 ~]# setfacl -x g:组名 文件名
#删除指定组的ACL权限
[root@CentOS7 ~]# setfacl -b 文件名
#删除文件的所有的ACL权限
3.开启ACL
- 临时
[root@CentOS7 ~]# mount -o remount acl /
- 永久
[root@CentOS7 ~]# vim /etc/fstab
UUID= / ext4 defaults,acl 0 0
[root@CentOS7 ~]# mount -o remount /
本文作者:.mignon
本文链接:https://www.cnblogs.com/mignon/p/18082800
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步