[root@itpro ~]# setfacl -m u:sqb:rwx /dirtest/
[root@itpro ~]# getfacl /dirtest/
getfacl: Removing leading '/' from absolute path names
# file: dirtest/
# owner: root
# group: root
user::rwx
user:sqb:rwx
group::r-x
group:admins:r-x
mask::rwx
other::rwx
[root@itpro ~]# ll -d /dirtest/
drwxrwxrwx+ 2 root root 4096 Mar 12 01:37 /dirtest/
(注:drwxrwxrwx+,这里不是按ugo权限排序,第一组rwx是文件所有者root的权限,第二组rwx是用户sqb的权限,第三组rwx是其他用户的权限,“+”表示acl设置的权限。
如果将其他用户的权限改回默认的r-x,会更易理解,如:
[root@itpro ~]# chmod o-w /dirtest/
[root@itpro ~]# ll -d /dirtest/
drwxrwxr-x+ 2 root root 4096 Mar 12 01:37 /dirtest/
)
4.测试
依次切换到用户sqa、sqb、sqc,查看其对dirtest文件夹的操作权限,
[root@itpro ~]# su sqa
[sqa@itpro root]$ ls /dirtest/
t01 t02
[sqa@itpro root]$ touch /dirtest/t03
touch: cannot touch `/dirtest/t03': Permission denied
[sqa@itpro root]$ exit
exit
[root@itpro ~]# su sqb
[sqb@itpro root]$ ls /dirtest/
t01 t02
[sqb@itpro root]$ touch /dirtest/t03
[sqb@itpro root]$ ls /dirtest/
t01 t02 t03
[sqb@itpro root]$ exit
exit
[root@itpro ~]# su sqc
[sqc@itpro root]$ ls /dirtest/
t01 t02 t03
[sqc@itpro root]$ touch /dirtest/t04
[sqc@itpro root]$ ls /dirtest/
t01 t02 t03 t04
[sqc@itpro root]$ ll /dirtest/
total 8
-rw-r--r--. 1 root root 17 Mar 5 07:04 t01
-rw-rw-r--. 1 sqb sqb 0 Mar 12 01:37 t02
-rw-rw-r--. 1 sqb sqb 0 Mar 12 02:22 t03
-rw-rw-r--. 1 sqc sqc 0 Mar 12 02:24 t04
[sqc@itpro root]$ exit
exit
(注:由于sqc不在用户组admins,所在sqc的权限为其他用户(ugo中的o)的权限,即rwx(实验一中设置的))
至此,实验结束,如果要恢复dirtest的访问权限为实验前的权限,可进行以下操作:
[root@itpro ~]# setfacl -b /dirtest/
(注:-b选项,表示清除指定对象的所有acl设置,慎用)
[root@itpro ~]# chmod o-w /dirtest/
(注:other的权限也改回r-x)
[root@itpro ~]# ll -d /dirtest/
drwxr-xr-x. 2 root root 4096 Mar 12 02:24 /dirtest/
[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
(注:可以看到,此时的文件权限恢复到常规状态)
