linux ACL權限規劃:getfacl,setfacl使用linux
ACL的使用vim
ACL即Access Control List 主要的目的是提供傳統的owner,group,others的read,write,execute權限以外的具體權限設置,ACL能夠針對單一用戶、單一文件或目錄來進行r,w,x的權限控制,對於須要特殊權限的使用情況有必定幫助。如,某一個文件,不讓單一的某個用戶訪問。
ACL使用兩個命令來對其進行控制
getfacl:取得某個文件/目錄的ACL設置項目
setfacl:設置某個文件/目錄的ACL設置項目
setfacl 參數
-m:設置後續acl參數
-x:刪除後續acl參數
-b:刪除所有的acl參數
-k:刪除默認的acl參數
-R:遞歸設置acl,包括子目錄
-d:設置默認acl
例:建立一文件test,將其權限修改成777,並查看其默認ACL權限配置
[root@Self-study ~]# touch /test
[root@Self-study ~]# chmod 777 /test
[root@Self-study ~]# getfacl /test //得到文件的ACL權限
getfacl: Removing leading '/' from absolute path names
# file: test //文件名
# owner: root //文件所屬者
# group: root //文件所屬組
user::rwx //文件所屬者權限
group::rwx //同組用戶權限
other::rwx //其它者權限
[root@Self-study ~]#
能夠看到其它者的權限也是可讀可寫可執行,能夠自行測試,如今咱們修改其ACL策略,使用用戶code只有讀取的權限
[root@Self-study ~]# setfacl -m u:code:r /test
[root@Self-study ~]# ll /test
-rwxrwxrwx+ 1 root root 1 Apr 11 07:25 /test //能夠看到權限的最後多了一個」+」號
[root@Self-study ~]#
如今再次查看一下此文件的ACL屬性
[root@Self-study ~]# getfacl /test
getfacl: Removing leading '/' from absolute path names
# file: test
# owner: root
# group: root
user::rwx
user:code:r-- //能夠看到code單獨的權限爲r--
group::rwx
mask::rwx
other::rwx
[root@Self-study ~]#
注:code的權限並非只根據ACL配置來決定的,它是由code用戶基本權限與配置的ACL權限的「與」運算決定的,即other:rwx 與 code:r-- = code:r--
如今使用code用戶,測試是否可寫
在寫文件時,會出現-- INSERT -- W10: Warning: Changing a readonly file提示。
除了對單個用戶進行設置外,還能夠對用戶組、有效權限(mask)進行設置如對用戶組設置: g:[用戶組]:[rwx]
注:有效權限(mask) 即用戶或組所設置的權限必需要存在於mask的權限設置範圍內纔會生效
如上面的/test文件,已經有了可讀權限,若是咱們把它的有效權限修改成只有寫權限,則設置的acl權限不在有效權限以內,則用戶code就不可能再查看/test文件中的內容了
[root@Self-study ~]# setfacl -m m:w /test //設置有效權限爲只寫
能夠查看/test acl屬性
[root@Self-study ~]# getfacl /test
getfacl: Removing leading '/' from absolute path names
# file: test
# owner: root
# group: root
user::rwx
user:code:r-- #effective:---
group::rwx #effective:-w-
mask::-w- //能夠看到有效權限已經修改爲功
other::rwx
[root@Self-study ~]#
使用code用戶查看文件內容,首先使用root用戶寫入一些內容,會使測試更加直觀
[root@Self-study ~]# echo "this is a test getfacl " >/test
[code@Self-study ~]$ vim /test
"/test" [Permission Denied] //能夠在最下面看到不容許訪問的提示,而且看不到任何內容
取消acl權限
[root@Self-study ~]# setfacl -x u:code /test //取消/test對用戶code的權限
[root@Self-study ~]# setfacl -x m /test //恢復有效權限
[root@Self-study ~]# getfacl /test
getfacl: Removing leading '/' from absolute path names
# file: test
# owner: root
# group: root
user::rwx
group::rwx
other::rwx
[root@Self-study ~]# ll /test
-rwxrwxrwx 1 root root 24 Apr 11 08:01 /test //已經能夠正常使用
[root@Self-study ~]#
至於另外的一些參數,本身嘗試使用!!