Linux访问控制列表(Access Control List,简称ACL)
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.ACL概述
ACL:Access Control List,实现灵活的权限管理
除了文件的所有者,所属组和其它人,可以对更多的用户设置权限
CentOS7 默认创建的xfs和ext4文件系统具有ACL功能
CentOS7 之前版本,默认手工创建的ext4文件系统无ACL功能,需手动增加 tune2fs –o acl /dev/sdb1 mount –o acl /dev/sdb1 /mnt/test
ACL生效顺序:所有者,自定义用户,自定义组,其他人
二.为jason用户对某个文件设置ACL权限
[root@node101.yinzhengjie.org.cn ~]# ll /data/ total 4 -rw-r--r--. 1 jason devops 0 Sep 10 06:34 jason.txt -rw-r--r--. 1 root devops 22 Sep 10 07:44 root.txt [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# setfacl -m u:jason:- /data/root.txt #这里我们对jason用户设置的权限为空("-"),即无权限访问"/data/root.txt"文件。 [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# ll /data/ total 4 -rw-r--r--. 1 jason devops 0 Sep 10 06:34 jason.txt -rw-r--r--+ 1 root devops 22 Sep 10 07:44 root.txt #大家注意,该文件设置后属性后面的"."变成了"+",说明设置ACL权限啦 [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# getfacl /data/root.txt #我们可以使用该命令查看相应的ACL设置 getfacl: Removing leading '/' from absolute path names # file: data/root.txt # owner: root # group: devops user::rw- user:jason:--- #我们发现jason用户对该文件的权限为0 group::r-- mask::r-- other::r-- [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# [root@node101.yinzhengjie.org.cn ~]# su -l jason Last login: Tue Sep 10 06:34:17 PDT 2019 on pts/0 [jason@node101.yinzhengjie.org.cn ~]$ [jason@node101.yinzhengjie.org.cn ~]$ ll /data/root.txt -rw-r--r--+ 1 root devops 22 Sep 10 07:44 /data/root.txt [jason@node101.yinzhengjie.org.cn ~]$ [jason@node101.yinzhengjie.org.cn ~]$ cat /data/root.txt cat: /data/root.txt: Permission denied [jason@node101.yinzhengjie.org.cn ~]$ [jason@node101.yinzhengjie.org.cn ~]$ echo "尹正杰到此一游">> /data/root.txt -bash: /data/root.txt: Permission denied [jason@node101.yinzhengjie.org.cn ~]$
三.为属组对某个文件设置ACL权限
四.