linux之ACL授权

ACL授权比chmod更加灵活,也更加精细化,在进行授权操作时,推荐使用ACL方式。

 

一.添加权限

setfacl -m u:username:rwx dir/file  #此时会看的dir的权限多了一个加号

-m:添加或者修改

u[设置用户]:username[用户名]:rwx[设置权限]

g[设置组]:groupname[组名]:rwx[设置权限]

 

setfacl -m u:username:r -R dir #同时设置子目录下的权限

-R : 递归设置子目录下的权限

 

setfacl -m mask::r-- dir/file #设置mask的值,mask用于限制ACL_USER, ACL_GROUP和ACL_GROUP_OBJ的最大值

ACL_USER_OBJ : user::rwx  #文件所有者

ACL_USER:user : user:username:rwx

ACL_GROUP_OBJ : group::r-x #文件所属组

ACL_GROUP : group:groupname:r-x

 

 

二.查看权限

getfacl dir/file  #查看该目录被设置的所有acl权限

--omit-header :去掉头信息

 

三.删除权限

setfacl -x u:username dir/file #删除用户的权限

setfacl -x g:groupname dir/file #删除组的权限

setfacl -b dir/file  #删除该目录的全部acl权限

 

 

四.缺省的ACL设置

说明:如果希望在dir下建立的所有文件都可以被某一用户访问. 那么我们就应该对dir目录设置Default ACL。

setfacl -d -m user:username:rw dir

-d : 设置default acl

这样,任何人在该目录下创建的文件,都可以被username读写。

 

setfacl -k dir # 删除缺省acl设置

 

 

五.示例:

1.文件

1)ll -d testfile

drwxr-xr-x 2 root root 4096 1月  20 18:59 testfile

 

2)setfacl -m u:hanqunfeng:rwx testfile

 

3)ll -d testfile

drwxrwxr-x+ 2 root root 4096 1月  20 18:59 testfile

 

4)getfacl testfile

# file: test

# owner: root

# group: root

user::rwx

user:hanqunfeng:rwx

group::r-x

mask::rwx

other::r-x

 

说明:缺省的mask值也被设定为rwx.那是因为它规定了ACL_USER[user:hanqunfeng:rwx], ACL_GROUP和ACL_GROUP_OBJ[group::r-x]的最大值。

 

5)setfacl -m mask::r-- testfile

6)getfacl test

# file: test

# owner: root

# group: root

user::rwx

user:hanqunfeng:rwx             #effective:r--

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

mask::r--

other::r-x

 

说明:此时会看到相应的权限后面多出了#effective:r--,因为mask规定了ACL_USER, ACL_GROUP和ACL_GROUP_OBJ的最大值,所以实际的权限也是r--。

 

7)getfacl --omit-header testfile #去掉头信息

user::rwx

user:hanqunfeng:rwx             #effective:r--

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

mask::r--

other::r-x

 

8)setfacl -x u:hanqunfeng testfile

 

9)ll -d testfile

drwxr-xr-x+ 2 root root 4096 1月  20 18:59 testfile

 

10)setfacl -b testfile

 

11)ll -d testfile

drwxr-xr-x 2 root root 4096 1月  20 18:59 testfile

 

2.目录

1)setfacl -m u:hanqunfeng:rwx -R testdir

 

2)ll -d testdir

drwxrwxr-x+ 2 root root 4096 1月  20 18:59 testdir

 

3)getfacl --omit-header testdir

user::rwx

user:hanqunfeng:rwx

group::r-x

mask::rwx

other::r-x

 

4)setfacl -d -m u:hanqunfeng:rwx -R testdir

 

5)getfacl --omit-header testdir

user::rwx

user:hanqunfeng:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:hanqunfeng:rwx

default:group::r-x

default:mask::rwx

default:other::r-x

 

6)setfacl -b testdir

 

7)ll -d testfile

drwxr-xr-x 2 root root 4096 1月  20 18:59 testdir

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值