Linux常用命令-chacl

命令

chacl

描述

change the access control list of a file or directory
更改文件或目录的访问控制列表acl

用法

1
chacl [OPTION]... ACL FILE...

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Options:
-b 表示更改两个ACL,一个是文件访问ACL,一个是目录默认ACL
-d 只更改目录ACL
-R 只删除文件访问ACL
-D 只删除目录默认ACL
-B 删除所有ACL
-l 显示ACL权限,仅支持xfs文件系统
-r 递归设置目录ACL,仅支持xfs文件系统

ACL语法格式 tag:name:perm,每条ACL语句必须包括ugom四个tag
tag:
u or user: 表示用户ACL
g or group: 表示用户组ACL
o or other: 表示其他用户ACL
m or mask: 表示掩码ACL,即最大权限值
name: 指定用户名或用户组名,如果为空则表示默认是给文件或目录的所有者或所属组指定ACL权限
perm: 可以是rwx-组合

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$ echo aaa > file
$ mkdir dir
$ echo bbb > dir/file
$ ll
drwxr-xr-x 2 root root 18 Feb 24 17:48 dir/
-rw-r--r-- 1 root root 4 Feb 24 17:50 file
$ chacl -l file dir
file [u::rw-,g::r--,o::r--]
dir [u::rwx,g::r-x,o::r-x]
$ getfacl file dir
# file: file
# owner: root
# group: root
user::rw-
group::r--
other::r--

# file: dir
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
$ chacl -l file
file [u::rw-,g::r--,o::r--]
# 在原有权限的基础上添加用户usera可以读写的权限,并指定掩码权限m为rw
$ chacl u::rw-,g::r--,o::r--,u:usera:rw,m::rw file
# 添加了ACL权限的文件最后会显示一个+加号
$ ll file
-rw-r--r--+ 1 root root 4 Feb 24 18:02 file
$ chacl -l file
file [u::rw-,u:usera:rw-,g::r--,m::rw-,o::r--]
$ getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:usera:rw-
group::r--
mask::rw-
other::r--
# 更改掩码权限m为r,则会显示一个#effective权限即实际权限只有r,因为掩码权限限制了最高权限为r
$ chacl u::rw-,g::r--,o::r--,u:usera:rw,m::r file
$ getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:usera:rw- #effective:r--
group::r--
mask::r--
other::r--

# 设置目录的acl权限,添加usera的rwx权限
$ chacl u::rw-,g::r--,o::r--,u:usera:rwx,m::rwx dir
$ chacl -l dir
dir [u::rw-,u:usera:rwx,g::r--,m::rwx,o::r--]
$ getfacl dir
# file: dir
# owner: root
# group: root
user::rw-
user:usera:rwx
group::r--
mask::rwx
other::r--

# 清空ACL权限
$ chacl -B file dir
$ chacl -l file dir
file [u::rw-,g::r--,o::r--]
dir [u::rw-,g::r--,o::r--]