linux權限之facl
前面給大家分享了ugo和強制位和冒險位,有些時候我們利用之前講的權限有些需求滿足不了,比如說有一個文件對應其它人權限都爲只讀,jim用戶匹配ugo屬於other角色其權限爲只讀,但是我們需要讓Jim可以讀寫怎麼實現呢?帶着這些疑問大家可以看看下面的介紹.
facl基於文件的訪問控制列表 優先級比ugo高
想要使用fac首先需要檢測文件系統(分區)是否支持facl
tune2fs -l /dev/sda3 | grep acl
Default mount options: user_xattr acl
讓不支持acl的分區支持
mount -o remount,acl /boot/
查看文件是否設置有facl
ll
總用量 16
-rw-rw-rw-+ 1 user1 user1 4 11月 4 16:54 1.txt
上例中如果有+號表示設置了facl
查看文件是否設置了facl
getfacl a.txt
# file: a.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--
setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ...
-m 修改facl
-x 刪除某條facl
-b 刪除所有的facl
-d 設置目錄默認的facl
-R 表示遞歸設置
設置facl 針對a.txt文件爲redhat用戶設置特殊的權限
setfacl -m u:redhat:rwx a.txt
getfacl a.txt
# file: a.txt
# owner: root
# group: root
user::rw-
user:redhat:rwx
group::r--
mask::rwx
other::r--
setfacl -m u:user1:r-x a.txt
取消user1的facl
setfacl -x u:user1 a.txt
取消所有用戶的facl
setfacl -b a.txt
基於組的設置
setfacl -m g:IT:rwx a.txt
目錄的facl
目錄的default facl針對目錄有效 此設置對目錄本身無意義 其它人在此目錄下創建的文
件都繼承用戶對目錄設置的facl
設置目錄的facl
setfacl -m d:u:redhat:rwx test/
effective 最終效果
設置掩碼
setfac -m m::rw /tmp/test/1.txt