facl:file access control list 文件访问控制列表
facl用于实现除文件属主、文件属组、其它用户三者权限外的额外权限功能,所以当某个用户访问
文件时,系统是按如下顺序判定用户对此文件持有哪些权限的:
属主权限----facl----属组权限----其它用户 (当在facl中找到访问此文件用户的权限规则时,就以此权限
适用该用户,不再往后匹配权限)
于是出现了下面这种屏蔽某个用户的奇怪现象:
[nokk@centos6 tmp]$whoami //当前用户是nokk
nokk
[nokk@centos6 tmp]$ll
total 4
-rw-rw-rwx+ 1 tom tom 0 May 13 04:15 test.tom //其它用户对test.tom文件有可读可写可执行权限
[nokk@centos6 tmp]$cat test.tom //nokk用户cat test.tom时却提示无权限
cat: test.tom: Permission denied
[nokk@centos6 tmp]$
原因是test.tom设置了facl,查看如下
[nokk@centos6 tmp]$getfacl test.tom
# file: test.tom
# owner: tom
# group: tom
user::rw-
user:nokk:--- //facl规则里规定nokk用户对此文件无任何权限
group::rw-
mask::rw-
other::rwx
[nokk@centos6 tmp]$
根据上面权限判定顺序,当在facl中判定nokk用户对test.tom文件无任何权限时,就不会再去查看
“其它用户”的权限,所以,即使test.tom文件“其它用户”权限为可读可写可执行,但test.tom文件的属主
tom已经通过facl规则把nokk用户屏蔽了。
NAME
getfacl - get file access control lists
//getfacl命令可以查看某个文件的facl规则
NAME
setfacl - set file access control lists
//setfacl命令可以设置文件的facl规则
设置facl规则
[tom@centos6 tmp]$getfacl test.tom
# file: test.tom
# owner: tom
# group: tom
user::rw-
group::rw-
mask::rw-
other::rwx
[tom@centos6 tmp]$setfacl -m u:nokk:--- test.tom //设置facl规则,屏蔽nokk用户
[tom@centos6 tmp]$getfacl test.tom
# file: test.tom
# owner: tom
# group: tom
user::rw-
user:nokk:---
group::rw-
mask::rw-
other::rwx
[tom@centos6 tmp]$
*********************************************************************
移除facl规则
[tom@centos6 tmp]$getfacl test.tom
# file: test.tom
# owner: tom
# group: tom
user::rw-
user:nokk:---
group::rw-
mask::rw-
other::rwx
[tom@centos6 tmp]$setfacl -x u:nokk test.tom //移除facl规则中对nokk用户的限制
[tom@centos6 tmp]$getfacl test.tom
# file: test.tom
# owner: tom
# group: tom
user::rw-
group::rw-
mask::rw-
other::rwx
[tom@centos6 tmp]$
如遇如下setfacl设置facl时提示不支持,原因可能是当前目录所在分区不支持acl。
[root@centos6 data]#ll
total 16
drwx------. 2 root root 16384 May 14 00:49 lost+found
-rw-r--r--. 1 root root 0 May 14 00:50 test
[root@centos6 data]#getfacl test
# file: test
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@centos6 data]#setfacl -m u:tom:--- test
setfacl: test: Operation not supported
[root@centos6 data]#
如下有两种方法使其分区挂载后支持acl:
查看当前目录所在分区,并查看分区挂载选项是否有acl,没有的话说明分区被挂载后不支持acl
[root@centos6 data]#pwd //当前所在目录
/data
[root@centos6 data]#lsblk //查看块设备
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 3.7G 0 rom
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 19.5G 0 part /
├─sda3 8:3 0 19.5G 0 part /data //sda3分区挂载在/data目录下
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda6 8:6 0 13.4M 0 part
[root@centos6 data]#
[root@centos6 data]#tune2fs -l /dev/sda3 //查看sda3分区相关分区信息
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /data
Filesystem UUID: 41a53e2e-d77f-4ada-8712-826ac7ae2aaa
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none) //显示分区挂载选项没有acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
第一种方法:修改分区配置,使其挂载选项有acl,这样分区被挂载时就会自动带上acl选项挂载
[root@centos6 data]#tune2fs -o acl /dev/sda3 //修改使/sda3分区挂载选项支持acl
tune2fs 1.41.12 (17-May-2010)
[root@centos6 data]#tune2fs -l /dev/sda3 //再次查看分区信息
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /data
Filesystem UUID: 41a53e2e-d77f-4ada-8712-826ac7ae2aaa
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: acl //此时显示分区挂载选项支持acl
Filesystem state: clean
Errors behavior: Continue
卸载分区后重新挂载分区(因为只有重新挂载分区,才会使分区的挂载选项生效),再次
setfacl配置facl,验证是否能成功配置
[root@centos6 data]#cd
[root@centos6 ~]#umount /data //卸载分区
[root@centos6 ~]#mount /dev/sda3 /data //重新挂载分区
[root@centos6 ~]#cd /data
[root@centos6 data]#setfacl -m u:tom:--- test //已能正常设置facl
[root@centos6 data]#getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:tom:--- //已设置成功
group::r--
mask::r--
other::r--
[root@centos6 data]#
第二种方法:不修改分区挂载选项,而是挂载分区时手动加挂载选项,如下
[root@centos6 data]#setfacl -m u:tom:--- test
setfacl: test: Operation not supported
[root@centos6 data]#mount -o remount,acl /dev/sda3 /data //-o acl指明挂载选项acl
[root@centos6 data]#setfacl -m u:tom:--- test //setfacl设置成功
[root@centos6 data]#getfacl test
# file: test
# owner: root
# group: root
user::rw-
user:tom:--- //facl已生效
group::r--
mask::r--
other::r--
[root@centos6 data]#
通过第二种方法挂载后,可以如下查看:
[root@centos6 data]#mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sda3 on /data type ext4 (rw,acl) //括号里已显示分区已acl选项挂载
[root@centos6 data]#