CentOS下ACL权限控制详解

2020-01-30 15:44:05刘景俊

[root@localhost tmp]# su tkf

[tkf@localhost tmp]$ cd ./acldir/

[tkf@localhost acldir]$

=>用户tkf可以具有x权限可以进入目录

针对特定用户组

设置格式:g:用户组列表:权限

权限:rwx的组合形式

如用户组列表为空,代表设置当前文件所属用户组权限

举例:

[root@localhost tmp]# setfa

setfacl setfattr

[root@localhost tmp]# setfacl -m g:users:rx ./acldir/

[root@localhost tmp]# getfacl ./acldir/

# file: acldir

# owner: root

# group: root

user::rwx

user:tkf:--x

group::--- => 其他用户组(非acl设置)的权限

group:users:r-x => 记录users用户组针对此目录有acl权限

mask::r-x

other::---

针对有效权限设置

有效权限(mask)就是acl权限设置的极限值,也就是你所设置的acl权限一定是mask的一个子集,如果超出mask范围会将超出的权限去掉

设置格式:m:权限

权限:rwx的组合形式

举例:

[root@localhost tmp]# setfacl -m m:x ./acldir/

[root@localhost tmp]# getfacl ./acldir/

# file: acldir

# owner: root

# group: root

user::rwx

user:tkf:--x

group::r-x #effective:--x

group:users:r-x #effective:--x

mask::--x

other::---

针对默认权限设置

我们前面都是针对一个目录为一个用户(组)设置特定权限,但是如果这个目录下在新创建的文件是不具有这些针对这个用户的特定权限的。为了解决这个问题,就需要设置默认acl权限,使这个目录下新创建的文件有和目录相同的ACL特定权限

设置格式:d:[u|g]:用户(组)列表:权限

举例

[root@localhost tmp]# mkdir -m 711 ./defdir

[root@localhost tmp]# setfacl -m u:tkf:rxw ./defdir

[root@localhost tmp]# ll -d ./defdir/

drwxrwx--x+ 2 root root 4096 03-10 15:23 ./defdir/

=>目录权限具有acl特定权限(后面+)

[root@localhost tmp]# touch ./defdir/a.file;ll ./defdir/

-rw-r--r-- 1 root root 0 03-10 15:25 a.file

=>新创建的文件不具有acl特定权限(后面无+)

[root@localhost tmp]# setfacl -m d:u:tkf:rxw ./defdir

=>设置默认权限

[root@localhost tmp]

# getfacl ./defdir/

# file: defdir

# owner: root

# group: root

user::rwx

user:tkf:rwx

group::--x

mask::rwx

other::--x

default:user::rwx

default:user:tkf:rwx

default:group::--x

default:mask::rwx

default:other::--x

[root@localhost tmp]# touch ./defdir/b.file;ll ./defdir/

-rw-r--r-- 1 root root 0 03-10 15:25 a.file

-rw-rw----+ 1 root root 0 03-10 15:26 b.file

=>新创建文件默认带有acl特定权限

[root@localhost tmp]

# getfacl ./defdir/b.file