您的位置:首页 > 运维架构 > Linux

005. Linux基础五 P4 (ACL)

2020-11-09 23:59 1271 查看

1 ACL

ACL生效顺序:
所有者,自定义用户,所属组|自定义组,其他人

  • setfacl 可以设置ACL权限
  • getfacl 可查看设置的ACL权限
[root@centos7 dir3]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:docker1:---
group::r--
mask::r--
other::r--

[root@centos7 dir3]# setfacl -m g:admins:5 a
[root@centos7 dir3]# getfacl a
# file: a
# owner: root
# group: root
user::rw-
user:docker1:---
group::r--
group:admins:r-x
mask::r-x
other::r--

setfacl -b a
#清除所有ACL权限
getfacl file1 | setfacl --set-file=-file2
#复制file1的acl权限给file2

mask权限

mask 权限

  • mask只影响除所有者和other的之外的人和组的最大权限
  • mask需要与用户的权限进行逻辑与运算后,才能变成有限的权限(Effective Permission)
  • 用户或组的设置必须存在于mask权限设定范围内才会生效
    [root@centos7 dir3]# setfacl -m mask::rx a
    [root@centos7 dir3]# getfacl a
    # file: a
    # owner: root
    # group: root
    user::rw-
    user:docker1:---
    group::r--
    group:admins:r-x
    mask::r-x
    other::r--

    --set

    --set选项会把原有的ACL项都删除,用新的替代,需要注意的是一定要包含UGO的设置,不能象-m一样 只是添加ACL就可以

    setfacl --set u::rw,u:wang:rw,g::r,o::- file1

备份和还原ACL

#备份ACL getfacl -R /tmp/dir > acl.txt
#消除ACL权限 setfacl -R -b /tmp/dir
#还原ACL权限 setfacl -R --set-file=acl.txt
#还原ACL权限 setfacl --restore acl.txt
#查看ACL权限 getfacl -R /tmp/dir

练习

  1. 在/testdir/dir里创建的新文件自动属于webs组,组apps的成员如:tomcat能对这些新文件有读写 权限,组dbs的成员如:mysql只能对新文件有读权限,其它用户(不属于webs,apps,dbs)不能 访问这个文件夹
    [root@centos7 ~]# mkdir -p /testdir/dir
    [root@centos7 ~]# groupadd webs
    [root@centos7 ~]# chgrp webs /testdir/dir
    [root@centos7 ~]# chmod g+s /testdir/dir
    [root@centos7 ~]# groupadd apps;groupadd dbs
    [root@centos7 ~]# useradd -G apps tomcat;useradd -G dbs mysql
    [root@centos7 ~]# setfacl -d -m g:apps:rw /testdir/dir
    [root@centos7 ~]# setfacl -d -m g:dbs:r /testdir/dir
    [root@centos7 ~]# chmod o= /testdir/dir
  2. 误将 /bin/chmod 文件的执行权限删除,如何恢复?
    install /usr/bin/chmod -m 744 /chmod
    #在用install指令拷贝时指定权限,趁此时假如执行权限
    mv /chmod /usr/bin/chmod
    mv:是否覆盖"/usr/bin/chmod"? y
    #用mv命令将先前的chmod覆盖
    ll /usr/bin/chmod
    -rwxr--r--. 1 root root 58584 3月  16 16:39 /usr/bin/chmod
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: