getfacl显示文件访问控制列表

getfacl语法参数

getfacl [-dRLPvh] file...

getfacl [-dRLPvh]

--omit-header 过滤文件系统默认权限

-R 递归操作

示例:

[root@localhost ~]# getfacl file

# file: file

# owner: ley

# group: ley

user::rwx

group::---

other::---

说明:带#号的是系统默认权限,下面的才是ACL控制权限

[root@localhost ~]# getfacl --omit-header file

user::rwx

group::---

other::---


setfacl命令设置文件访问控制

setfacl语法参数

setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ...

etfacl --restore=file

命令参数单词描述
-mmodfiy修改文件ACL权限
-xremove移除文件ACL权限
-bremove-all移除文件所有ACL权限
-Rrescursive递归操作

setfacl命令示例:

问题:root用户有个file文件,它的系统默认权限是644,如果只限制ley普通用户对该文件进行读写。有以下几种方法:

  1. 将ley用户加入到root组(不安全)

  2. 将ley用户授予sudo权限(麻烦)

  3. root用户将file文件设置为666权限(其他普通用户也可读写)

说明:还是用setfacl写个ACL规则算了

[root@localhost ~]# getfacl file

# file: file

# owner: root

# group: root

user::rw- 6

group::r-- 4

other::r-- 4

说明:系统默认创建的文件为644权限,普通用户只有读写权限

[root@localhost ~]# setfacl -m u:ley:rw file  -->给属主添加ACL权限,或使用 u:ley:6

-m:修改文件ACL权限(上面有提到)

[root@localhost ~]# getfacl file

# file: file

# owner: root

# group: root

user::rw-

user:ley:rw-

group::r--

mask::rw-

other::r--



[ley@localhost ~]$ setfacl -m g:ley:rw file  -->给属组添加ACL权限,或使用 g:ley:6

[ley@localhost ~]$ getfacl file 

# file: file

# owner: ley

# group: ley

user::rw-

group::rw-

group:ley:rw-

mask::rw-

other::r--



[ley@localhost ~]$ setfacl -R -m u:ley:rw directory/  -->给目录递归添加属主ACL权限

[ley@localhost ~]$ getfacl directory/

# file: directory

# owner: ley

# group: ley

user::rwx

user:ley:rw-

group::rwx

mask::rwx

other::r-x

注意:添加了ACL权限的目录,在权限的最后一位有个加号(+)

[ley@localhost ~]$ ll -d directory/

drwxrwxr-x+ 2 ley ley 4096 11-12 11:44 directory/



删除ACL权限:

setgacl -x 属主(u)或属组(g):用户名 filename

说明:删除ACL权限,不需加权限,直接u:username filename

[ley@localhost ~]$ setfacl -x u:ley file

[ley@localhost ~]$ getfacl file

# file: file

# owner: ley

# group: ley

user::rw-

group::rw-

group:ley:rw-

mask::rw-

other::r--


[ley@localhost ~]$ setfacl -x g:ley file

[ley@localhost ~]$ getfacl file

# file: file

# owner: ley

# group: ley

user::rw-

group::rw-

mask::rw-

other::r--


情况所有ACL权限:

setgacl -b file

[ley@localhost ~]$ getfacl file

# file: file

# owner: ley

# group: ley

user::rw-

user:ley:rw-

group::rw-

group:ley:rw-

mask::rw-

other::r--


[ley@localhost ~]$ setfacl -b file

[ley@localhost ~]$ getfacl file

# file: file

# owner: ley

# group: ley

user::rw-

group::rw-

other::r--

说明:使用-b参数把ACL全部清空,但是不会影响系统默认权限