setfacl命令的基本用法

1、setfacl的用途

setfacl命令可以用来细分linux下的文件权限。
chmod命令可以把文件权限分为u,g,o三个组,而setfacl可以对每一个文件或目录设置更精确的文件权限。
换句话说,setfacl可以更精确的控制权限的分配。
比如:让某一个用户对某一个文件具有某种权限。

这种独立于传统的u,g,o的rwx权限之外的具体权限设置叫ACL(Access Control List)
ACL可以针对单一用户、单一文件或目录来进行r,w,x的权限控制,对于需要特殊权限的使用状况有一定帮助。
如,某一个文件,不让单一的某个用户访问。


2、setfacl的用法

3、几个例子

查看一个test文件的acl

修改之后再查看:

再看一个例子:

[root@localhost ~]# getfacl test     #查看acl
# file: test
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@localhost ~]# setfacl -m u:tank:rx test   #给tank用户向test文件增加读和执行的acl规则
[root@localhost ~]# getfacl test    #查看acl
# file: test
# owner: root
# group: root
user::rw-
user:tank:r-x      #已加入
group::r--
mask::r-x
other::r--

[root@localhost ~]# setfacl -m u::rwx test   #设置默认用户,读,写,可执行
[root@localhost ~]# getfacl test
# file: test
# owner: root
# group: root
user::rwx
user:tank:r-x
group::r--
mask::r-x
other::r--

[root@localhost ~]# setfacl -b test     #清除所有acl
[root@localhost ~]# getfacl test 
# file: test
# owner: root
# group: root
user::rwx
group::r--
other::r--

[root@localhost ~]# setfacl -m u:tank:rx test      #给tank用户向test文件增加读和执行的acl规则
[root@localhost ~]# setfacl -m u:testtank:rx test  #给testtank用户向test文件增加读和执行的acl规则
[root@localhost ~]# getfacl test
# file: test
# owner: root
# group: root
user::rwx
user:testtank:r-x
user:tank:r-x
group::r--
mask::r-x
other::r--


[root@localhost ~]# setfacl -x u:tank test    #清除tank用户,对test文件acl规则
[root@localhost ~]# getfacl test
# file: test
# owner: root
# group: root
user::rwx
user:testtank:r-x
group::r--
mask::r-x
other::r--

设置组的话只需要把setfacl -m u::rwx 中的u改为g即可,大致差不多。

设置mask的话,setfacl -m u::rwx 中的u改为m,并且这个可不针对用户和组哦,其他的大致差不多。

在使用-R时,记得放在-m前面,否则不可以地

使用-d的话,就会把默认的都加上去,针对目录哦。

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值