文件基本权限-ACL

文件权限管理之: ACL设置基本权限(r、w、x)

UGO设置基本权限: 只能一个用户,一个组和其他人
ACL 设置基本权限: r,w,x
//Access Control List 访问控制列表

ACL基本用法

设置:
[root@localhost ~]# touch /home/test.txt
[root@localhost ~]# ll /home/test.txt
-rw- r--r-- 1 root root 0 10-26 13:59 /home/test.txt

[root@localhost ~]# getfacl /home/test.txt
[root@localhost ~]# setfacl -m u:alice:rw /home/test.txt //增加用户alice权限
[root@localhost ~]# setfacl -m u:jack:- /home/test.txt //增加用户jack权限
[root@localhost ~]# setfacl -m o::rw /home/test.txt

查看/删除:
[root@localhost ~]# ll /home/test.txt
-rw- rw-r-- + 1 root root 0 10-26 13:59 /home/test.txt
[root@localhost ~]# getfacl /home/test.txt
[root@localhost ~]# setfacl -m g:hr:r /home/test.txt
[root@localhost ~]# setfacl -x g:hr /home/test.txt //删除组hr的acl权限

[root@localhost ~]# setfacl -b /home/test.txt //删除所有acl权限 

 ACL高级用法

mask:
用于临时降低用户或组( 除属主和其他人)的权限
建议:为了方便管理文件权限,其他人的权限置为空

示例:mask值影响用户权限的举例
[root@localhost ~]# touch /home/file1
[root@localhost ~]# setfacl -m u:gougou:rw /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::rw-
user:gougou:rw-
group::r--
mask::rw-
other::r--

[root@localhost ~]# setfacl -m m::r /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::rw-
user:gougou:rw- #effective:r--
group::r--
mask::r--
other::r--

[root@localhost ~]# su - gougou
[gougou@localhost ~]$ cat /home/file1
[gougou@localhost ~]$ vim /home/file1 

使用vim打开文件之后无法对文件进行修改

[root@localhost ~]# setfacl -m o::rwx /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::---
user:alice:rw-
group::---
mask::rw-
other::rwx
[root@localhost ~]# setfacl -m m::r /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::---
user:alice:rw- #effective:r-- 有效权限:r
group::---
mask::r--
other::rwx
[alice@localhost ~]$ cat /home/file1
333
[alice@localhost ~]$ vim /home/file1
使用vim打开文件之后无法对文件进行修改,因为我们的mask值是r,不是空的,所以alice用户不会继承other的权限
[root@localhost ~]# setfacl -m m::- /home/file1
[root@localhost ~]# getfacl /home/file1
getfacl: Removing leading '/' from absolute path names
# file: home/file1
# owner: root
# group: root
user::---
user:alice:rw- #effective:---
group::---
mask::---
other::rwx

[root@localhost ~]# su - alice
[alice@localhost ~]$ cat /home/file1
333
ddd
[alice@localhost ~]$ vim /home/file1
这个时候使用vim打开文件的时候就可以对文件的内容进行修改了,因为mask值为空,所以alice会继承other的身份


总结:
mask的值不为空的时候,单独设置用户或者是组的acl权限就受自己的权限的影响,不包括user(属主)和other(其他人),但是如果将mask的值设置为空,单独设置过acl权限的用户会受other的权限的影响。

default: 继承(默认)
要求: 希望alice能够对/tmp/dir100以及以后在/tmp/dir100下新建的文件有读、写、执行权限

[root@localhost tmp]# mkdir dir100
[root@localhost tmp]# touch dir100/file1 dir100/file2

一: 赋予alice对/tmp/dir100以及目录下以存在的文件和文件夹读、写、执行权限
[root@localhost ~]# setfacl -R -m u:alice:rwx /tmp/dir100
[root@localhost tmp]# getfacl dir100/file1
# file: dir100/file1
# owner: root
# group: root
user::rw-
user:alice:rwx
group::r--
mask::rwx
other::r--

[root@localhost tmp]# getfacl dir100/file2
# file: dir100/file2
# owner: root
# group: root
user::rw-
user:alice:rwx
group::r--
mask::rwx
other::r--

[root@localhost tmp]# touch dir100/file3
[root@localhost tmp]# getfacl dir100/file3
# file: dir100/file3
# owner: root
# group: root
user::rw-
group::r--
other::r--


二: 赋予alice对以后在/tmp/dir100下新建的文件有读、写、执行权限 (使alice的权限继承)
[root@localhost ~]# setfacl -m d:u:alice:rwx /tmp/dir100
[root@localhost tmp]# getfacl dir100/
# file: dir100/
# owner: root
# group: root
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:alice:rwx
default:group::r-x
default:mask::rwx
default:other::r-x

[root@localhost tmp]# touch dir100/file4
[root@localhost tmp]# getfacl dir100/file4
# file: dir100/file4
# owner: root
# group: root
user::rw-
user:alice:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--

注意:文件的x权限不能随便给的,所以系统会自动的将文件的x权限减掉

[root@localhost tmp]# mkdir dir100/dir200
[root@localhost tmp]# getfacl dir100/dir200/
# file: dir100/dir200/
# owner: root
# group: root
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:alice:rwx
default:group::r-x
default:mask::rwx
default:other::r-x

[root@localhost tmp]# mkdir dir100/dir200/dir300
[root@localhost tmp]# getfacl dir100/dir200/dir300
# file: dir100/dir200/dir300
# owner: root
# group: root
user::rwx
user:alice:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:alice:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
[root@localhost tmp]# touch dir100/dir200/dir300/file1
[root@localhost tmp]# getfacl dir100/dir200/dir300/file1
# file: dir100/dir200/dir300/file1
# owner: root
# group: root
user::rw-
user:alice:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值