对文件或者目录具体设置ACL功能以及查看具体的ACL配置,
用到setfacel 和getfacl两个命令。
下面进行ACL权限设置实验。
准备工作
先创建三个普通用户sqa、sqb、sqc及用户组admins,并将用户sqa、sqb加入到该用户组;
在/下创建待测试的文件夹dirtesta及其子文件。
[root@itpro ~]# useradd sqa
[root@itpro ~]# useradd sqb
[root@itpro ~]# useradd sqc
[root@itpro ~]# groupadd admins
[root@itpro ~]# usermod -G admins sqa
[root@itpro ~]# usermod -G admins sqb
[root@itpro ~]# mkdir /dirtest
[root@itpro ~]# touch /dirtest/t01
[root@itpro ~]# ll -d /dirtest/
drwxr-xr-x. 2 root root 4096 Mar 12 01:08 /dirtest/
[root@itpro ~]# ll /dirtest/
total 4
-rw-r--r--. 1 root root 17 Mar 5 07:04 t01
实验一
求要:其他用户对文件夹dirtest有读写权限,但用户sqa没有任何权限
解决方法:给ugo中的o开放读写权限,使用acl限制特定用户sqa
1.先查看当前dirtest的acl
[root@itpro ~]# getfacl /dirtest/
getfacl: Removing leading '/' from absolute path names
# file: dirtest/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
[root@itpro ~]# ll -d /dirtest/
drwxr-xr-x. 2 root root 4096 Mar 12 01:08 /dirtest/
2.更改dirtest的访问权限
[root@itpro ~]# chmod o+w /dirtest/
(注:给其他用户增加“写”权限)
[root@itpro ~]# setfacl -m u:sqa:--- /dirtest/
(注:不给用户sqa任何权限)
3.再次查看当前的dirtest权限
[root@itpro ~]# getfacl /dirtest/
getfacl: Removing leading '/' from absolute path names
# file: dirtest/
# owner: root
# group: root
user::rwx
user:sqa:---
group::r-x
mask::r-x
other::rwx
[root@itpro ~]# ll -d /dirtest/
drwxr-xrwx+ 2 root root 4096 Mar 12 01:08 /dirtest/
(注:drwxr-xrwx+,这里仍然是按ugo权限排序,最后的“+”,表示设置了acl)
4.测试
切换到用户sqa
[root@itpro ~]# su sqa
[sqa@itpro root]$ ls /dirtest/
ls: cannot open directory /dirtest/: Permission denied
[sqa@itpro root]$ cd /dirtest/
bash: cd: /dirtest/: Permission denied
切换到用户sqb
[sqa@itpro root]$ exit
exit
[root@itpro ~]# su sqb
[sqb@itpro root]$ ls /dirtest/
t01
[sqb@itpro root]$ cd /dirtest/
[sqb@itpro dirtest]$ touch t02
[sqb@itpro root]$ ls /dirtest/
t01 t02
切换回root用户
[sqb@itpro root]$ exit
exit
[root@itpro ~]#
