- ACL :Access Control List,实现灵活的权限管理
- 除了文件的所有者,所属组和其它人,可以对更多的用户设置权限
- CentOS7 默认创建的xfs 和ext4文件系统具有ACL 功能
- CentOS7 之前版本,默认手工创建的ext4 文系统无ACL功能, 需手动增加
tune2fs –o acl /dev/sdb1(分区)
mount –o acl /dev/sdb1 /mnt/test
- ACL 生效顺序:所有者,自定义用户,自定义组,其他人
范例:
mount -o acl /directory
getfacl file |directory
setfacl -m u:wang:rwxfile|directory
setfacl -Rm g:sales:rwX directory
setfacl -M file.acl file|directory
setfacl -m g:salesgroup:rw file|directory
setfacl -m d:u:wang:rx directory
setfacl -x u:wang file |director
setfacl -X file.acl directory
ACL特殊权限特点
- ACL 文件上的group 权限是mask 值(自定义用户,自定义组,拥有组的最大权限), 而非传统的组权限
- getfacl 可看到特殊权限:flags
- 通过ACL 赋予目录默认x 权限 ,目录内文件也不会继承x权限
- base ACL 不能删除
- setfacl -k dir 删除默认ACL 权限
- setfacl –b file1 清除所有ACL 权限
- getfacl file1 | setfacl --set-file=- file2 复制file1
的的acl权限给file2
[root@VinnyWang app]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:wang:rwx
group::r--
mask::rwx
other::r--
[root@VinnyWang app]# touch b
[root@VinnyWang app]# getfacl a |setfacl --set-file=- b
[root@VinnyWang app]# getfacl b
# file: b
# owner: root
# group: root
user::rw-
user:wang:rwx
group::r--
mask::rwx
other::r--
- mask 只影响除所有者和other的之外的人和组的最大权限
- Mask 需要与用户的权限进行逻辑与运算后,才能变成有限的权限(Effective Permission)
- 用户或组的设置必须存在于mask 权限设定 范围内才会 生效
- setfacl -m mask::rx file
- --set 选项会把原有的ACL 项都删除,用新的替代,需要注意的是一定要包含UGO 的设置,不能象-m一样只是添加ACL
备份和恢复ACL
在cp -p 的复制上时,就是带有特殊权限的复制
getfacl -R /tmp/dir1 > acl.txt
setfacl -R -b /tmp/dir1
setfacl -R --set-file=acl.txt /tmp/dir1
setfacl --restore acl.txt
getfacl -R /tmp/dir1
网友评论