15 權限管理及作業(作業單獨一篇)
一、雜項知識整理
1、訪問控制列表:ACL:Access Control List,實現靈活的權限管理。
除了文件的所有者,所屬組和其它人,可以對更多的用戶設置權限。
centos7.0之后默認創建的ext4文件系統有ACL功能,centos7.x之前的版本,默認手工創建的ext4文件系統無ACL功能,需要手動添加:
查看磁盤acl權限:dumpe2fs -h /dev/sda#:
Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean
tune2fs -o acl /dev/sdb1
mount -o acl /dev/sdb1 /mnt
二、命令詳解及事例
1、setfacl命令
文件名 :查看acl權限
-m 設置acl權限
u:USER:rx /FILE
u:USER:rx -R /DIR/
d:u:USER:rx -R /DIR
d:default 使文件夾下的新建的文件或目錄默認有此屬性acl權限
-k DIR 刪除默認的acl權限
即使默認的acl權限給了x,文件也不會繼承x權限。
-Rm g:USER:rwX /DIR
設定支持X,使文件夾有而文件沒有acl權限
-x 刪除指定的acl權限
setfacl -x g:USER /FILE
-b 刪除所有的acl權限
-d 設定默認的acl權限,清空所有acl權限
逐個用戶刪除acl時,文件屬性上的+不會消除,用-d變為默認,+就會消除
-R 遞歸設定
-M 調用文件:按照格式寫入后setacl -M file.acl FILE/DIR
格式例如: u:wang:0
g:g1:rwx
u:tom:rw
getfacl file1 | setfacl –set-file=- file2 復制file1的acl權限給file2
setfacl –set u::rw,u:wang:rw,g::r,o::- file1情況所有acl權限,用新的替代,必須包含所有ugo的設置。
2、getfacl FILE 查看acl權限屬性:
其中mask是最大值限定,可以設置以保證acl權限不會過大,原理:mask與賦予的acl權限相與(屏蔽權限,與umask同樣),mask與賦予的acl權限同時存在時才會賦予此權限,也就是兩個為真才為真,但是當mask為rwx時,不論賦予的何種權限,結果都為賦予的權限本身。
設定mask權限:setfacl -m mask:rwx FILE
mask值影響的不包括u和o。
3、cp和mv都支持acl但是cp命令需要加-p,但是tar等常見的備份工具不會保留acl信息。
三、課后練習及作業
1、pdf 6最后一個問題:
[root@localhost testdir]# ll 總用量 72 -r---w-rw-. 1 root root 4 8月 3 17:04 a -r---w-rw-. 1 root root 4 8月 3 17:04 a~ dr---wxrw-. 2 root root 4096 8月 3 17:03 aa -r---w-rw-. 1 root root 0 8月 3 17:53 b drwxr-xr-x. 3 root root 4096 7月 30 13:50 copytest drwxrws---+ 2 root g1 4096 8月 3 17:42 data drwx------. 2 root root 16384 7月 19 21:07 lost+found drwxr-xr-x. 2 root root 12288 8月 1 13:54 shelltest -rw-r--r--. 1 root root 32 7月 29 18:20 string.txt -rw-r--r--. 1 root root 246 8月 2 22:45 user drwxr-xr-x. 3 root root 4096 8月 3 13:12 user.dir -rw-r--r--. 1 root root 195 7月 28 19:37 userinfo -rw-r--r--. 1 root root 78 8月 2 22:53 userpasswd [root@localhost testdir]# lsattr ---------------- ./string.txt ----------I----- ./shelltest ---------------- ./b ---------------- ./data ---------------- ./copytest ---------------- ./userinfo ---------------- ./user ---------------- ./lost+found ---------------- ./a~ ---------------- ./user.dir ----ia---------- ./aa -----a---------- ./a ---------------- ./userpasswd [root@localhost testdir]# getfacl data/ # file: data/ # owner: root # group: g1 # flags: -s- user::rwx group::-wx group:g2:rw- group:g3:r-- mask::rwx other::---
原創文章,作者:SilencePavilion,如若轉載,請注明出處:http://www.www58058.com/28045