加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

setfacl语法2

发布时间:2020-12-14 01:30:40 所属栏目:Linux 来源:网络整理
导读:setfacl命令可以用来细分linux下的文件权限。chmod命令可以把文件权限分为u,g,o三个组,而setfacl可以对每一个文件或目录设置更精确的文件权限。换句话说,setfacl可以更精确的控制权限的分配。比如:让某一个用户对某一个文件具有某种权限。这种独立于传统
setfacl命令可以用来细分linux下的文件权限。
chmod命令可以把文件权限分为u,g,o三个组,而setfacl可以对每一个文件或目录设置更精确的文件权限。
换句话说,setfacl可以更精确的控制权限的分配。
比如:让某一个用户对某一个文件具有某种权限。

这种独立于传统的u,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设置
[[email?protected]?~]#?cd?/test/
[[email?protected]?test]#?touch?test.txt
[[email?protected]?test]#?echo?123??>?test.txt?
[[email?protected]?test]#?cat?test.txt?
123
[[email?protected]?test]#?chmod?777?test.txt?
[[email?protected]?test]#?ll
总用量?0
-rwxrwxrwx.?1?root?root?0?2月???6?20:40?test.txt
[[email?protected]?test]#?getfacl?test.txt?
#?file:?test.txt??????????????????????????//文件名
#?owner:?root????????????????????????????//文件所属者
#?group:?root?????????????????????????????//文件所属组
user::rwx????????????????????????????????????//文件所属者权限
group::rwx?????????????????????????????????//同组用户权限
other::rwx??????????????????????????????????/其它者权限

现在我们让handsome用户只有读取的权限

[[email?protected]?test]#?setfacl?-m?u:handsome:r?test.txt?
[[email?protected]?test]#?ll
总用量?4
-rwxrwxrwx+?1?root?root?0?2月???6?20:40?test.txt????????//权限的最后多了一个“+”
[[email?protected]?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用户验证一下:
[[email?protected]?test]#?su?-?handsome?
[[email?protected]?~]$?cat?/test/test.txt?
123
[[email?protected]?~]$?echo?456?>>?/test/test.txt?
-bash:?/test/test.txt:?权限不够


除了对某个文件的单个用户进行权限设置外,还可以对某个组进行同样的设置:g:[用户组]:[rwx]

还能对有效权限(mask)进行设置:有效权限(mask)?即用户或组所设置的权限必须要存在于mask的权限设置范围内才会生效
??????????????

最后取消ACL权限:
[[email?protected]?test]#?setfacl?-x?u:handsome?test.txt?
[[email?protected]?test]#?ll
总用量?8
-rwxrwxrwx+?1?root?root?4?2月???6?20:47?test.txt

删除所有acl
[[email?protected]?test]#?setfacl?-b?test.txt?
[[email?protected]?test]#?ll
总用量?4
-rwxrwxrwx.?1?root?root?4?2月???6?20:47?test.txt?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读