zoukankan      html  css  js  c++  java
  • Linux下的ACL

    ACL理论概述

    9位的属主/属组/其他人访问控制系统已经得到证明是强大的,足以满足大多数管理方面的需求。

    事实上,在所有非UNIX操作系统上都采用了一种实质上更为复杂的方式来管理对于文件的访问:访问控制列表(access control list),简称ACL。ACL不限制长度,可以包含用于多个用户或者用户组的权限规定。更先进的系统能让系统管理员指定部分权限的集合或者否定方式的权限。

    因为在POSIX规范中增加了ACL,所以许多UNIX的变体也开始支持一种相当标准的ACL机制,这种机制和传统的UNIX 9位权限模式平行地发挥左右。

    Linux的ACL主要是对标准的9位权限模型直接进行扩展。ACL可以按照用户和用户组的任意组合独立地设置rwx权限位。

    ACL的主要命令

    getfacl 命令可以显示一个文件当前的ACL

    $ getfacl --help
    getfacl 2.2.49 -- 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

    setfacl 命令可以修改或者设置文件当前的ACL

    $ setfacl --help
    setfacl 2.2.49 -- 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

    ACL实例

    1. ACL随着chmod命令对权限模式位的修改而自动更新

    $ touch example
    $ ls -l example 
    -rw-rw-r-- 1 eric eric 0 Dec 17 07:34 example
    $ getfacl example 
    # file: example
    # owner: eric
    # group: eric
    user::rw-
    group::rw-
    other::r--
    $ chmod 640 example 
    $ getfacl --omit-header example 
    user::rw-
    group::r--
    other::---

    2. Mask规定了ACL能够给单个组和用户访问权限的上限。扩充上一个例子里的ACL,让它包括对某个特定用户和组的ACL,setfacl会自动提供一个合适的mask

    $ ls -l example 
    -rw-r----- 1 eric eric 0 Dec 17 07:34 example
    $ setfacl -m user::r,user:squid:rw,group:squid:rw example 
    $ ls -l example 
    -r--rw----+ 1 eric eric 0 Dec 17 07:34 example
    $ getfacl --omit-header example 
    user::r--
    user:squid:rw-
    group::r--
    group:squid:rw-
    mask::rw-
    other::---

    如上所示,setfacl命令产生了一个mask,让ACL中赋予的所有权限都发生了作用。在尝试访问文件的时候,要把有效UID同该文件属主的UID进行对比。如果他们一样,那么ACL中user::项权限就决定了能否访问。否则,匹配某个特定用户的ACL项,那么ACL项连同ACL的mask就一起决定了能否访问。如果没有特定于某个用户,那么文件系统会尝试找有效的组ACL项;如果还没有匹配项,那么在用other::这个ACL项。

    3. 如果在一个有ACL的文件上,用chmod来控制组的访问权限,那么修改只对mask有影响。

    $ getfacl --omit-header example 
    user::r--
    user:squid:rw-
    group::r--
    group:squid:rw-
    mask::rw-
    other::---
    $ ls -l example 
    -r--rw----+ 1 eric eric 0 Dec 17 07:34 example
    $ chmod 770 example 
    $ ls -l example 
    -rwxrwx---+ 1 eric eric 0 Dec 17 07:34 example
    $ getfacl --omit-header example 
    user::rwx
    user:squid:rw-
    group::r--
    group:squid:rw-
    mask::rwx
    other::---

    这里的ls输出有点误导性。尽管表面上看给组权限,但是没有人因为是组成员而有权执行该文件,为了让组有这样的权限,必须用setfacl编辑ACL本上。

  • 相关阅读:
    写一些,给2013
    C# DateTime变量不能赋null值
    31222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
    王爽《汇编语言》第三版 第十五章 外中断
    王爽《汇编语言》第三版 第十四章 端口
    王爽《汇编语言》第三版 第十二章 内中断
    王爽《汇编语言》第三版 第十一章 标志寄存器
    王爽《汇编语言》第三版 第十章 call和ret指令
    王爽《汇编语言》第三版 第九章 转移指令的原理
    王爽《汇编语言》第三版 第八章 数据处理的两个基本问题
  • 原文地址:https://www.cnblogs.com/oskb/p/3478642.html
Copyright © 2011-2022 走看看