簡介

  1. 什麼是 ACL (Access Control List)?
    1. 提供傳統的 owner,group,others 的 read,write,execute 權限之外的細部權限設定。
    2. ACL 可以針對單一使用者,單一檔案或目錄來進行 r, w, x 的權限規範。
    3. ACL 主要可以針對以下項目來控制權限:
      1. 使用者 (user):可以針對使用者來設定權限;
      2. 群組 (group):針對群組為對象來設定其權限;
      3. 預設屬性 (mask):針對在該目錄下在建立新檔案/目錄時,規範新資料的預設權限。
  2. 安裝 acl
    [root@kvm8 ~]# dnf install acl
    
  3. setfacl 輔助說明
    setfacl 2.3.2 -- 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
    
    選項說明:
    -m :設定後續的 acl 參數給檔案使用,不可與 -x 合用;
    -x :刪除後續的 acl 參數,不可與 -m 合用;
    -b :移除所有的 ACL 設定參數;
    -k :移除預設的 ACL 參數;
    -R :遞迴設定 acl,即包括次目錄都會被設定;
    -d :設定『預設 acl 參數』,只對目錄有效,在該目錄新建的資料會引用此預設值
    
  4. 設定檔案 acl
    setfacl -m u[ser]:someuser:perms  file
    setfacl -m g[roup]:somegroup:perms file
    
  5. getfacl 輔助說明
    [root@kvm8 ~]# getfacl --help
    getfacl 2.3.2 -- 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
          --one-file-system   skip files on different filesystems
      -p, --absolute-names    don't strip leading '/' in pathnames
      -v, --version           print version and exit
      -h, --help              this help text