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]#