简介: setfaclSETFACL(1) Access Control Lists SETFACL(1)NA...


SETFACL(1)                   Access Control Lists                   SETFACL(1)


       setfacl - set file access control lists


       setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ...

       setfacl --restore=file


       This utility sets Access Control Lists (ACLs) of files and directories.
       On the command line, a sequence of commands is followed by  a  sequence
       of  files  (which  in  turn can be followed by another sequence of com-
       mands, ...).

       The options -m, and -x expect an ACL on the command line. Multiple  ACL
       entries are separated by comma characters (‘,’). The options -M, and -X
       read an ACL from a file or from standard input. The ACL entry format is
       described in Section ACL ENTRIES.

       The  --set and --set-file options set the ACL of a file or a directory.
       The previous ACL is replaced.  ACL  entries  for  this  operation  must
       include permissions.

       The  -m  (--modify)  and -M (--modify-file) options modify the ACL of a
       file or directory.  ACL entries for this operation must include permis-

       The  -x  (--remove)  and  -X (--remove-file) options remove ACL enries.
       Only ACL entries without the perms field are  accepted  as  parameters,
       unless POSIXLY_CORRECT is defined.

       When  reading  from files using the -M, and -X options, setfacl accepts
       the output getfacl produces.  There is at most one ACL entry per  line.
       After  a  Pound  sign  (‘#’),  everything  up to the end of the line is
       treated as a comment.

       If setfacl is used on a file system which does not support  ACLs,  set-
       facl operates on the file mode permission bits. If the ACL does not fit
       completely in the permission bits, setfacl modifies the file mode  per-
       mission bits to reflect the ACL as closely as possible, writes an error
       message to standard error, and returns with an exit status greater than

       The  file  owner  and  processes  capable of CAP_FOWNER are granted the
       right to modify ACLs of a file. This is analogous  to  the  permissions
       required  for  accessing the file mode. (On current Linux systems, root
       is the only user with the CAP_FOWNER capability.)

       -b, --remove-all
           Remove all extended ACL entries. The base ACL entries of the owner,
           group and others are retained.

       -k, --remove-default
           Remove  the  Default ACL. If no Default ACL exists, no warnings are

       -n, --no-mask
           Do not recalculate the effective rights mask. The default  behavior
           of  setfacl  is  to  recalculate  the ACL mask entry, unless a mask
           entry was explicitly given.  The mask entry is set to the union  of
           all  permissions  of the owning group, and all named user and group
           entries. (These are  exactly  the  entries  affected  by  the  mask

           Do recalculate the effective rights mask, even if an ACL mask entry
           was explicitly given. (See the -n option.)

       -d, --default
           All operations apply to the Default ACL. Regular ACL entries in the
           input  set are promoted to Default ACL entries. Default ACL entries
           in the input set are discarded. (A warning is issued if  that  hap-

           Restore a permission backup created by ‘getfacl -R’ or similar. All
           permissions of a complete directory subtree are restored using this
           mechanism.  If the input contains owner comments or group comments,
           and setfacl is run by root, the owner and owning group of all files
           are  restored  as  well.  This  option  cannot  be mixed with other
           options except ‘--test’.

           Test mode. Instead of changing the ACLs of any files, the resulting
           ACLs are listed.

       -R, --recursive
           Apply  operations  to  all  files and directories recursively. This
           option cannot be mixed with ‘--restore’.

       -L, --logical
           Logical walk, follow symbolic links. The  default  behavior  is  to
           follow  symbolic link arguments, and to skip symbolic links encoun-
           tered  in  subdirectories.  This  option  cannot  be   mixed   with

       -P, --physical
           Physical  walk,  skip  all symbolic links. This also skips symbolic
           link arguments.  This option cannot be mixed with ‘--restore’.

           Print the version of setfacl and exit.

           Print help explaining the command line options.

       --  End of command line options. All remaining  parameters  are  inter-
           preted as file names, even if they start with a dash.

       -   If  the  file name parameter is a single dash, setfacl reads a list
           of files from standard input.

       The setfacl utility recognizes the following ACL entry formats  (blanks
       inserted for clarity):

       [d[efault]:] [u[ser]:]uid [:perms]
              Permissions  of  a  named user. Permissions of the file owner if
              uid is empty.

       [d[efault]:] g[roup]:gid [:perms]
              Permissions of a named group. Permissions of the owning group if
              gid is empty.

       [d[efault]:] m[ask][:] [:perms]
              Effective rights mask

       [d[efault]:] o[ther][:] [:perms]
              Permissions of others.

       Whitespace between delimiter characters and non-delimiter characters is

       Proper ACL entries including permissions are used  in  modify  and  set
       operations.  (options  -m,  -M, --set and --set-file).  Entries without
       the perms field are used for deletion of entries (options -x and -X).

       For uid and gid you can specify either a name or a number.

       The perms field is a combination of characters that indicate  the  per-
       missions: read (r), write (w), execute (x), execute only if the file is
       a directory or already  has  execute  permission  for  some  user  (X).
       Alternatively, the perms field can be an octal digit (0-7).

       Initially,  files  and  directories  contain  only  the  three base ACL
       entries for the owner, the group, and others. There are some rules that
       need to be satisfied in order for an ACL to be valid:

       *   The three base entries cannot be removed. There must be exactly one
           entry of each of these base entry types.

       *   Whenever an ACL contains named user entries or named group objects,
           it must also contain an effective rights mask.

       *   Whenever an ACL contains any Default ACL entries, the three Default
           ACL base entries (default owner, default group, and default others)
           must also exist.

       *   Whenever  a  Default ACL contains named user entries or named group
           objects, it must also contain a default effective rights mask.

       To help the user ensure  these  rules,  setfacl  creates  entries  from
       existing entries under the following conditions:

       *   If  an  ACL contains named user or named group entries, and no mask
           entry exists, a mask entry containing the same permissions  as  the
           group  entry is created. Unless the -n option is given, the permis-
           sions of the mask entry are further adjusted to include  the  union
           of  all  permissions affected by the mask entry. (See the -n option

       *   If a Default ACL entry is created, and the Default ACL contains  no
           owner, owning group, or others entry, a copy of the ACL owner, own-
           ing group, or others entry is added to the Default ACL.

       *   If a Default  ACL  contains  named  user  entries  or  named  group
           entries, and no mask entry exists, a mask entry containing the same
           permissions as the default Default  ACL’s  group  entry  is  added.
           Unless  the  -n  option is given, the permissions of the mask entry
           are further adjusted to inclu  de  the  union  of  all  permissions
           affected by the mask entry. (See the -n option description).


       Granting an additional user read access
              setfacl -m u:lisa:r file

       Revoking  write  access  from all groups and all named users (using the
       effective rights mask)
              setfacl -m m::rx file

       Removing a named group entry from a file’s ACL
              setfacl -x g:staff file

       Copying the ACL of one file to another
              getfacl file1 | setfacl --set-file=- file2

       Copying the access ACL into the Default ACL
              getfacl --access dir | setfacl -d -M- dir


       If the environment variable POSIXLY_CORRECT  is  defined,  the  default
       behavior  of  setfacl  changes as follows: All non-standard options are
       disabled.  The ‘‘default:’’ prefix is disabled.  The -x and -X  options
       also accept permission fields (and ignore them).


       Andreas Gruenbacher, <>.

       Please  send  your  bug reports, suggested features and comments to the
       above address.


       getfacl(1), chmod(1), umask(1), acl(5)

May 2000                      ACL File Utilities                    SETFACL(1)


configuring access control lists(ACLs)

entry-type:[UID OR GID]:perm.其中perm代表一些执行权限如读,写,执行,或由0-7的数字来代表
ACL entry type有下面几种:
4,u[ser]::UID:perm or u[ser]:username:perm
5,g[roup]:GID:perm or g[roup]:groupname:perm
getfacl filename(s):展示文件上的ACL
setfacl -m acl_entries filename:在文件上创建或更改ACL
setfacl -s acl_entries filename:用新的ACL代替旧的ACL
setfacl -d acl_entries filename:删除文件上一个或多个ACL
setfacl -f acl_file filename
setfacl -r filename:重新计算ACL mask.
1,判断文件是否有一个ACL,常用的方法是进入到相应的目录,用ls -l命令展开,如果在权限后带一个加号,说明有ACL.不过用ls命令得不到实际的ACL,推荐用getfacl命令.
2,列出一个ACL,常用的命令格式是:getfacl [-a | -d] filename1 [filename2...]
要注意一点这里的ACL mask跟umask不相同,umask值是默认的文件或目录拥有的权限.而ACL mask对每个文件或目录能不相同.
3,更改一个ACL,这也是常用的方法.常用的格式是:setfacl -m acl_entry,filename
比如:# setfacl -m u:userb:7 file2
4,删除一个ACL,常用的命令格式是:setfacl -d acl_entry filename
比如:# setfacl -d u:usera file2
5,替换一个ACL,常用的命令格式是:setfacl -s u::perm,g::perm,o:perm,m:perm,[u:UID:perm],[g:GID:perm] filename
比如:# setfacl -s u::rwx,g::rw-,o:r--,m;rw-,u:usera:rwx file1
6,更改ACL mask.
常用的命令格式是:setfacl -r -m acl_entry filename.其中-r选项是指接受最大的effictive值.-m是更改当前的ACL
比如:# setfacl -r -m u:usera:7 file1
7,复制一个文件的ACL到另一个文件.常用的命令格式是:getfacl filename1 |setfacl -f - filename2
8,创建默认的ACL.要注意的是设置默认的ACL只针对目录操作,而且在为一个新增的用户或组之前必须设置默认的user,group,other,ACL mask值.
比如:#setfacl -m d:u::rwx,d:g::r-x,d:o:r-x,d:m:r-x dir1,其中d代表default.
设置了这个之后,才能够添加新的用户,比如:# setfacl -m default:user:usera:rwx dir1

Shell Linux 数据安全/隐私保护
6.4.3 文件特殊权限: SUID, SGID, SBIT
6.4.3 文件特殊权限: SUID, SGID, SBIT
27 0
vr&ar 数据安全/隐私保护
Unix 数据安全/隐私保护 Shell
Linux 数据安全/隐私保护