1. 程式人生 > >setfacl命令基本用法

setfacl命令基本用法

txt apply user ech -bash text his 生效 trie

setfacl命令可以用來細分linux下的文件權限。 chmod命令可以把文件權限分為u,g,o三個組,而setfacl可以對每一個文件或目錄設置更精確的文件權限。 換句話說,setfacl可以更精確的控制權限的分配。 比如:讓某一個用戶對某一個文件具有某種權限。 這種獨立於傳統的u,g,o的rwx權限之外的具體權限設置叫ACL(Access Control List) ACL可以針對單一用戶、單一文件或目錄來進行r,w,x的權限控制,對於需要特殊權限的使用狀況有一定幫助。 如,某一個文件,不讓單一的某個用戶訪問。 setfacl 參數 Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ... -m, --modify=acl modify the current ACL(s) of file(s) -M, --modify-file=file read ACL entries to modify from file -x, --remove=acl remove entries from the ACL(s) of file(s) -X, --remove-file=file read ACL entries to remove from file -b, --remove-all remove all extended ACL entries -k, --remove-default remove the default ACL --set=acl set the ACL of file(s), replacing the current ACL --set-file=file read ACL entries to set from file --mask do recalculate the effective rights mask -n, --no-mask don't recalculate the effective rights mask -d, --default operations apply to the default ACL -R, --recursive recurse into subdirectories -L, --logical logical walk, follow symbolic links -P, --physical physical walk, do not follow symbolic links --restore=file restore ACLs (inverse of `getfacl -R') --test test mode (ACLs are not modified) -v, --version print version and exit -h, --help this help text 例子:在/test 下建立一個test文件 將權限改為777 並查看其ACL設置 [root@localhost ~]# cd /test/ [root@localhost test]# touch test.txt [root@localhost test]# echo 123 > test.txt [root@localhost test]# cat test.txt 123 [root@localhost test]# chmod 777 test.txt [root@localhost test]# ll 總用量 0 -rwxrwxrwx. 1 root root 0 2月 6 20:40 test.txt [root@localhost test]# getfacl test.txt # file: test.txt //文件名 # owner: root //文件所屬者 # group: root //文件所屬組 user::rwx //文件所屬者權限 group::rwx //同組用戶權限 other::rwx /其它者權限 現在我們讓handsome用戶只有讀取的權限 [root@localhost test]# setfacl -m u:handsome:r test.txt [root@localhost test]# ll 總用量 4 -rwxrwxrwx+ 1 root root 0 2月 6 20:40 test.txt //權限的最後多了一個“+” [root@localhost test]# getfacl test.txt # file: test.txt # owner: root # group: root user::rwx user:handsome:r-- //handsome的權限為r group::rwx mask::rwx other::rwx 通過handsome用戶驗證一下: [root@localhost test]# su - handsome [handsome@localhost ~]$ cat /test/test.txt 123 [handsome@localhost ~]$ echo 456 >> /test/test.txt -bash: /test/test.txt: 權限不夠 除了對某個文件的單個用戶進行權限設置外,還可以對某個組進行同樣的設置:g:[用戶組]:[rwx] 還能對有效權限(mask)進行設置:有效權限(mask) 即用戶或組所設置的權限必須要存在於mask的權限設置範圍內才會生效 最後取消ACL權限: [root@localhost test]# setfacl -x u:handsome test.txt [root@localhost test]# ll 總用量 8 -rwxrwxrwx+ 1 root root 4 2月 6 20:47 test.txt 刪除所有acl [root@localhost test]# setfacl -b test.txt [root@localhost test]# ll 總用量 4 -rwxrwxrwx. 1 root root 4 2月 6 20:47 test.txt //文件權限後面的“+”沒了


setfacl命令基本用法