• [RH134] 5-ACL


    1.Linux ACL

    ACL:访问控制列表。

    ACL可以对文件的访问权限做更细粒度的设置。

    1)获取某个文件的权限信息

    [root@centos7 etc]# getfacl hosts     
    # file: hosts
    # owner: root
    # group: root
    user::rw-
    group::r--
    other::r--

    可以看到/etc/hosts的user、group、other的权限。

    2)对某个单独用户设置单独的文件权限

    [root@centos7 test]# setfacl -m u:leo:rw- hosts

    给用户leo单独设置hosts的读写权限。添加权限使用"-m"选项。

    [root@centos7 test]# getfacl hosts
    # file: hosts
    # owner: root
    # group: root
    user::rw-
    user:leo:rw-
    group::r--
    mask::rw-
    other::r--

    可以看到,单独的一条针对用户leo对应hosts文件的权限。

    此时,我们看hosts文件的权限:

    [root@centos7 test]# ll
    total 4
    -rw-rw-r--+ 1 root root 158 Mar 24 11:00 hosts

    可以看到后面多了一个"+"号,这个"+"号表示权限可以展开,意思是除了原本的user、group、other权限,现在还有额外的细粒度权限。

    3)删除权限

    [root@centos7 test]# setfacl -x u:leo hosts

    删除权限,使用"-x"选项。

    4)添加某个单独组的权限

    [root@centos7 test]# setfacl -m g:leo:r-- hosts
    [root@centos7 test]# getfacl hosts
    # file: hosts
    # owner: root
    # group: root
    user::rw-
    group::r--
    group:leo:r--
    mask::r--
    other::r--

    删除:

    [root@centos7 test]# setfacl -x g:leo hosts

    2.mask权限设置

    当我们想要在某个时间段让某个文件对所有用户都实行一个权限,则使用mask权限(相当于在其上加一层遮罩)。

    我们查看hosts文件的权限的时候,可以看到一个默认的mask权限条目:

    [root@centos7 test]# getfacl hosts         
    # file: hosts
    # owner: root
    # group: root
    user::rw-
    group::r--
    mask::r--
    other::r--

    这个mask权限主要对单独的权限条目起掩盖作用。例如,leo用户有个单独的读写权限:

    [root@centos7 test]# getfacl hosts             
    # file: hosts
    # owner: root
    # group: root
    user::rw-
    user:leo:rw-
    group::r--
    mask::rw-
    other::r--

    此时,可以看到mask权限自动变为"rw-"权限。如果我们修改mask权限为"r--",即权限小于之前的权限:

    [root@centos7 test]# setfacl -m m::r-- hosts    
    [root@centos7 test]# getfacl hosts          
    # file: hosts
    # owner: root
    # group: root
    user::rw-
    user:leo:rw-                    #effective:r--
    group::r--
    mask::r--
    other::r--

    可以看到,leo用户单独权限被限制在了"r--",此时的leo用户无法对hosts进行写入操作了。

    但这个#effective权限是临时的,如果我们对任意权限条目进行修改(例如使用setfacl命令),则mask权限失效,变回原本的权限(rw-,此时不会影响其他权限)。

    3.默认权限

    针对目录的权限设置。

    默认权限的意思是设置某个目录中创建的新文件对某个目标有一个默认的权限(预先指定一个默认权限,对所有新创文件有效)。

    例如,我们有个/opt/test目录:

    [root@centos7 opt]# getfacl test     
    # file: test
    # owner: root
    # group: root
    user::rwx
    group::r-x
    other::r-x

    这个目录对于用户leo来说,可以进入test目录,但无法在其中创建文件,因为(other)没有写权限:

    [leo@centos7 test]$ touch aa
    touch: cannot touch ‘aa’: Permission denied

    我们为test目录创建一个默认权限:

    [root@centos7 opt]# setfacl -m d:u:leo:rwx test

    再看test的权限:

    [root@centos7 opt]# getfacl test
    # file: test
    # owner: root
    # group: root
    user::rwx
    group::r-x
    other::r-x
    default:user::rwx
    default:user:leo:rwx
    default:group::r-x
    default:mask::rwx
    default:other::r-x

    这个默认权限的意思是,不管谁在test目录下创建文件或目录,对于leo用户来说都是"rwx"权限的。但是test目录本身的权限对于leo用户还是"r-x",即不能在其中创建文件或目录。

    ===

  • 相关阅读:
    apply和call详解
    this用法
    jquery的each()详细介绍
    摹客食堂|你真的会做交付文档吗?
    资源分享|找不到素材?这份免费APP UI Kit资源大礼包送给你!
    功能播报|PRD可以在线审阅啦!让文档管理更轻松~
    工具推荐|2019年UI设计师必备工具清单
    案例分析|最佳倒数计时器设计分析【附原型实例】
    摹客食堂|新"葵花宝典"--用户体验设计知识大全
    灵感专题|2019年优秀网页设计作品赏析#9月
  • 原文地址:https://www.cnblogs.com/leokale-zz/p/12543688.html
Copyright © 2020-2023  润新知