zoukankan      html  css  js  c++  java
  • ALC访问控制列表实现现有权限不变添加用户访问

    ALC

    • 访问控制列表,可以理解为自定义权限。

    • 针对特定的文件和文件夹给特定的用户设定需要的权限。

    应用场景

    • 在保持源文件权限及拥有者和用户组不变的情况下,添加可访问用户
    • chmod更改的权限,恢复的时候难,acl恢复原始权限更方便

    相关命令

    • sefacl 设置访问控制列表
    [07:44:04 root@C8-3-55 ~]#setfacl --help
    setfacl 2.2.53 -- set file access control lists
    Usage: setfacl [-bkndRLP] { -m|-M|-x|-X ... } file ...
      -m, --modify=acl        modify the current ACL(s) of file(s)
      -M, --modify-file=file  read ACL entries to modify from file
      -x, --remove=acl        remove entries from the ACL(s) of file(s)
      -X, --remove-file=file  read ACL entries to remove from file
      -b, --remove-all        remove all extended ACL entries
      -k, --remove-default    remove the default ACL
          --set=acl           set the ACL of file(s), replacing the current ACL
          --set-file=file     read ACL entries to set from file
          --mask              do recalculate the effective rights mask
      -n, --no-mask           don't recalculate the effective rights mask
      -d, --default           operations apply to the default ACL
      -R, --recursive         recurse into subdirectories
      -L, --logical           logical walk, follow symbolic links
      -P, --physical          physical walk, do not follow symbolic links
          --restore=file      restore ACLs (inverse of `getfacl -R')
          --test              test mode (ACLs are not modified)
      -v, --version           print version and exit
      -h, --help              this help text
    
    • getfacl 查看已设置的访问控制列表
    
    [07:45:37 root@C8-3-55 ~]#getfacl --help
    getfacl 2.2.53 -- get file access control lists
    Usage: getfacl [-aceEsRLPtpndvh] file ...
      -a,  --access           display the file access control list only
      -d, --default           display the default access control list only
      -c, --omit-header       do not display the comment header
      -e, --all-effective     print all effective rights
      -E, --no-effective      print no effective rights
      -s, --skip-base         skip files that only have the base entries
      -R, --recursive         recurse into subdirectories
      -L, --logical           logical walk, follow symbolic links
      -P, --physical          physical walk, do not follow symbolic links
      -t, --tabular           use tabular output format
      -n, --numeric           print numeric user/group identifiers
      -p, --absolute-names    don't strip leading '/' in pathnames
      -v, --version           print version and exit
      -h, --help              this help text
    

    ACL 生效顺序

    所有者->自定义用户->所属组|自定义组,其他人

    实例:使用chmod取消chmod程序本身的执行权限,用acl重新添加执行权限

    [07:46:13 root@C8-3-55 ~]#ll /usr/bin/chmod  ## 查看chmod程序本身的原始权限
    -rwxr-xr-x. 1 root root 76904 5月  11 2019 /usr/bin/chmod ## 原始权限为755
    [07:57:12 root@C8-3-55 ~]#chmod a-x /usr/bin/chmod ## 使用chmod删除程序本身的执行权限
    [07:57:42 root@C8-3-55 ~]#ll /usr/bin/chmod ## 再次查看chmod程序的权限
    -rw-r--r--. 1 root root 76904 5月  11 2019 /usr/bin/chmod ## 删除执行权限后chmod程序权限变为644
    [07:57:44 root@C8-3-55 ~]#chmod a+x /usr/bin/chmod ## 使用chmod试图重新加回执行权限
    -bash: /usr/bin/chmod: 权限不够 ## 因chmod已失去执行权限,程序无法运行
    
    [07:59:56 root@C8-3-55 ~]#setfacl -m u:root:rwx /usr/bin/chmod ## 使用acl为用户root添加rwx权限
    [08:00:06 root@C8-3-55 ~]#ll /usr/bin/chmod ## 再次查看chmod权限
    -rw-rwxr--+ 1 root root 76904 5月  11 2019 /usr/bin/chmod ## 未变化,但在末尾出现+
    [08:01:35 root@C8-3-55 ~]#getfacl /usr/bin/chmod ## 使用getfacl查看chmod的acl权限
    getfacl: Removing leading '/' from absolute path names
    # file: usr/bin/chmod
    # owner: root
    # group: root
    user::rw-
    user:root:rwx ## 自定义权限添加成功
    group::r--
    mask::rwx
    other::r--
    
    [08:01:52 root@C8-3-55 ~]#chmod a+x /usr/bin/chmod ## 再次使用chmod添加x权限
    [08:02:40 root@C8-3-55 ~]#ll /usr/bin/chmod ## 再次查看chmod权限
    -rwxrwxr-x+ 1 root root 76904 5月  11 2019 /usr/bin/chmod ## x权限添加成功,但仍有+标识
    [08:03:14 root@C8-3-55 ~]#setfacl -b /usr/bin/chmod ## -b选项清空已添加acl
    [08:03:41 root@C8-3-55 ~]#ll /usr/bin/chmod ## 最后查看chmod权限
    -rwxr--r-x. 1 root root 76904 5月  11 2019 /usr/bin/chmod ## 完好如初
    
    * * * 胖并快乐着的死肥宅 * * *
  • 相关阅读:
    浅谈ASP.NET内部机制(四)
    用正则表达式看.NET编程正则核心对象详解(三 )
    【讨论】对技术的掌握到底应该又多深?
    掌握XML系列(三)创建格式良好的饿XML文档 续编
    浅谈ASP.NET的内部机制(一)
    浅谈ASP.NET内部机制(三)
    浅谈ASP.NET的内部机制(二)
    小工具大智慧
    老生常谈:抽象工厂模式
    又说:程序员的成长过程
  • 原文地址:https://www.cnblogs.com/bpzblog/p/14488516.html
Copyright © 2011-2022 走看看