1.了解setfacl用法
# setfacl [选项] 文件或目录名称
选项说明:
-m : 修改acl策略
-x : 去掉某个用户或者某个组的权限
-b : 删除所有的acl策略
-R :递归,通常用在文件夹
2.首先,我们创一个在家目录下的新文件夹a:
[root@linux121 ~]# mkdir /root/a
[root@linux121 ~]# ll
总用量 20
drwxr-xr-x 2 root root 6 3月 3 16:37 a
-rw-------. 1 root root 1257 9月 14 04:15 anaconda-ks.cfg
drwxr-xr-x 2 root root 6 11月 22 10:11 Desktop
drwxr-xr-x 2 root root 6 11月 22 10:11 Documents
drwxr-xr-x 2 root root 6 11月 22 10:11 Downloads
-rw-r--r-- 1 root root 49 11月 3 21:24 dtr.txt
drwxr-xr-x 3 root root 18 11月 22 09:22 itcast
drwxr-xr-x 2 root root 6 11月 22 15:43 itheima
drwxr-xr-x 2 root root 6 11月 22 10:11 Music
drwxr-xr-x 2 root root 6 11月 22 10:11 Pictures
drwxr-xr-x 2 root root 6 11月 22 10:11 Public
-rwxrwx--T 1 root root 0 6月 18 2025 shr.txt
drwxr-xr-x 2 root root 6 11月 22 10:11 Templates
-rw-r--r-- 1 root root 144 3月 2 15:29 test.txt
drwxr-xr-x 2 root root 6 11月 22 10:11 Videos
-rw-r--r-- 1 root root 5383 11月 3 21:21 wc.jar
3.在a文件夹中创建一个叫做cal.txt 的文件:
[root@linux121 ~]# touch /root/a/cal.txt
[root@linux121 ~]# cd /root/a
[root@linux121 a]# ll
总用量 0
-rw-r--r-- 1 root root 0 3月 3 16:40 acl.txt
4.获取 acl.txt 文件的acl权限:
[root@linux121 a]# getfacl acl.txt
# file: acl.txt //文件名
# owner: root // 文件拥有者
# group: root // 文件所属的组
user::rw- //文件所属者权力
group::r-- //文件所属组权限
other::r-- // 其他用户权力
5.让usershr 只有读取的权限:
[root@linux121 a]# setfacl -m u:usershr:r acl.txt
[root@linux121 a]# ll
总用量 0
-rw-r--r--+ 1 root root 0 3月 3 16:40 acl.txt // 多了一个加号
[root@linux121 a]# getfacl acl.txt
# file: acl.txt
# owner: root
# group: root
user::rw-
user:usershr:r-- // usershr拥有此权限
group::r--
mask::r-- //mask 权限,指的是用户或群组能拥有的最大 ACL 权限,也就是说,给用户或群组设定的 ACL 权限不能超过 mask 规定的权限范围,超出部分做无效处理。
other::r--
6.除了让某个用户有特定的权限 我们还可以让某个组有特定的权限
g:[用户组]:[rwx] //与上文 setfacl -m u:usershr:r acl.txt 相同,将u改为g即可
若要取消权限则
[root@linux121 a]# setfacl -x u:usershr /root/acl.txt