ACL设置技巧

 setfacl [-bkRd] [{-m|-x} acl参数]  目标文件名

  参数:

 

   -m:设置后续的acl参数给文件使用,不可以与-x合用。

   -x:删除后续的acl参数,不可与-m合用。

   -b:删除所有的acl设置参数。

   -k:删除默认的acl参数。

   -R:递归设置acl

   -d:设置默认的acl参数,只对目录有效。在该目录下新建的数据会引用此默认值。

 

1

[root@www test]# getfacl /home/test

getfacl: Removing leading '/' from absolute path names

# file: home/test

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

 

[root@www test]#  setfacl -m u:helen:rw /home/test   

[root@www test]# getfacl /home/test

getfacl: Removing leading '/' from absolute path names

# file: home/test

# owner: root

# group: root

user::rwx

user:helen:rw-

group::r-x

mask::rwx

other::r-x

2

[root@www test]# touch testACL2

[root@www test]# getfacl testACL2

# file: testACL2

# owner: root

# group: root

user::rw-

group::r--

other::r--

[root@www test]# setfacl -m u:centos:rw -R /home/test

//赋予testACL2的父目录/home/test具有递归ACL权限,

//此时子目录和和子文件也具有了该ACL权限,查看testACL2,也具有了该ACL权限

 [root@www test]# getfacl testACL2

# file: testACL2

# owner: root

# group: root

user::rw-

user:centos:rw-

group::r--

mask::rw-

other::r—

3

[root@www test]# touch testACL3

[root@www test]# getfacl testACL3                //新建testACL3文件,并查看其ACL权限

//此时testACL5文件并不具有父目录的ACL权限:u:centos:rw

//由此可见,递归ACL权限只对已存在的子目录和子文件有效,而对新建的子目录和文件无效

# file: testACL3

# owner: root

# group: root

user::rw-

group::r--

other::r--

 

4)默认ACL权限

默认ACL权限的作用是:如果给父目录设定了ACL权限,那么父目录中所有新建的子文件都会继承父目录的ACL权限

[root@www test]# setfacl -m d:u:samlee:rw -R /home/test

[root@www test]# getfacl /home/test

getfacl: Removing leading '/' from absolute path names

# file: home/test

# owner: root

# group: root

user::rwx

user:centos:rw-

user:helen:rw-

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:samlee:rw-

default:group::r-x

default:mask::rwx

default:other::r-x

 

[root@www test]# touch testACL5

[root@www test]# getfacl testACL5

# file: testACL5

# owner: root

# group: root

user::rw-

user:samlee:rw-

group::r-x                      #effective:r--

mask::rw-

other::r—

 

注意:并且此时会有如下情况:新建的子目录的权限继承了父目录默认的ACL权限,并且该子目录的默认目录也继承了父母目录的默认目录的ACL权限

[root@www test]# mkdir testdir

[root@www test]# getfacl testdir

# file: testdir

# owner: root

# group: root

user::rwx

user:samlee:rw-

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:samlee:rw-

default:group::r-x

default:mask::rwx

default:other::r-x

注意:子目录testdir下载新建子目录testdir2,其权限继承了testdir的默认权限,但是testdir2不在有默认的ACL权限

[root@www test]# cd testdir

[root@www testdir]# touch testdir2

[root@www testdir]# getfacl testdir2

# file: testdir2

# owner: root

# group: root

user::rw-

user:samlee:rw-

group::r-x                      #effective:r--

mask::rw-

other::r—

5)删除默认目录

[root@www testdir]# cd ..

[root@www test]# setfacl -k testdir

 [root@www testdir]# getfacl testdir

getfacl: testdir: No such file or directory

 [root@www test]# getfacl testdir

# file: testdir

# owner: root

# group: root

user::rwx

user:samlee:rw-

group::r-x

mask::rwx

other::r-x

 

6)删除某项权限

[root@www test]# setfacl -m u:userzs:rwx,u:samlee:rwx testACL2

[root@www test]# getfacl testACL2

# file: testACL2

# owner: root

# group: root

user::rw-

user:centos:rw-

user:samlee:rwx

user:userzs:rwx

group::r--

mask::rwx

other::r—

 

//删除用户userzs对文件testACL2ACL权限

[root@www test]# setfacl -x u:userzs testACL2

[root@www test]# getfacl testACL2

# file: testACL2

# owner: root

# group: root

user::rw-

user:centos:rw-

user:samlee:rwx

group::r--

mask::rwx

other::r—

 

//删除文件testACL2所有的ACL权限

[root@www test]# setfacl -b testACL2

[root@www test]# getfacl testACL2

# file: testACL2

# owner: root

# group: root

user::rw-

group::r--

other::r--

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值