ACL (Access Control List) is the Access Control List. The rwx permission is set in detail for a single user, a single file or directory. Users, groups, and default attribute masks can be set. ACL is an additional function supported by Linux system permissions and must be supported by the file system, such as ReiserFS, EXT2, EXT3, EXT4, JFS, and XFS. * ACL:
- [Root @ rhel6 ~] # Mount-o acl/dev/iscsi/sharedisk/data/
- [Root @ rhel6 ~] # Mount | grep sharedisk
- /Dev/mapper/iscsi-sharedisk on/data type ext4 (rw, acl)
- Note: If you use the tune2fs command to enable the partition ACL function, you cannot use the mount command.
- [Root @ rhel6 ~] # Tune2fs-o acl/dev/iscsi/sharedisk
- [Root @ rhel6 ~] # Tune2fs-l/dev/iscsi/sharedisk | grep-I "default mount option"
- Default mount options: acl
- [Root @ rhel6 ~] # Umount/data/
- [Root @ rhel6 ~] # Mount/dev/iscsi/sharedisk/data/
- [Root @ rhel6 ~] # Mount | grep sharedisk
- /Dev/mapper/iscsi-sharedisk on/data type ext4 (rw)
ACL-related setting command getfacl: obtains the ACL settings of a file or directory. setfac: sets ACL settings for files or directories. chacl: Same as setfacl. It is also used to set ACL settings (not commonly used ).
- [Root @ rhel6 data] # setfacl -- help
- Setfacl 2.2.49 -- set file access control lists
- Usage: setfacl [-bkndRLP] {-m |-M |-x |-X...} file...
- -M, -- modify = acl: changes the ACL rules of files or directories.
- -M, -- modify-file = file: Read ACL settings from a file and modify the ACL rules of the current file or directory as a template.
- -X, -- remove = acl: delete a specified ACL rule for a file or directory.
- -X, -- remove-file = file Read ACL settings from a file and delete the ACL rules of the current file or directory as a template
- -B, -- remove-all Delete all ACL rules of a file or directory
- -K, -- remove-default delete default ACL rules for files or directories
- -- Set = acl: sets the ACL rules for the current file.
- -- Set-file = file: Read ACL rules from a file to set ACL rules for the current file or directory
- -- The mask recalculates valid permissions, even if the ACL mask is explicitly specified
- -N, -- no-mask do not recalculate valid permissions. By default, setfacl recalculates the ACL mask, unless the mask is explicitly formulated.
- -D, -- default: Set the default ACL rules for the directory (only valid for the Directory)
- -R, -- recursive Processing
- -L, -- logical walk, follow symbolic links
- -P, -- physical walk, do not follow symbolic links
- -- Restore = file restore ACLs (inverse of 'getfacl-R ')
- -- Test mode (ACLs are not modified)
Note: If the ACL is set for a directory or file, a "+" number will appear at the last digit of the attribute. To view the exact permissions of the file or directory group, use the getfacl command.
- Directory:
- [Root @ rhel6 data] # mkdir acl_dir
- [Root @ rhel6 data] # ll-d acl_dir
- Drwxr-xr-x. 2 root 1024 Mar 24 :29 acl_dir/
- [Root @ rhel6 data] # getfacl acl_dir/
- # File: acl_dir
- # Owner: root "Basic Rules"
- # Group: root
- User: rwx
- Group: r-x "Default rule"
- Other: r-x
- [Root @ rhel6 data] # su-user1
- [User1 @ rhel6 ~] $ Touch/data/acl_dir/acl_user1
- Touch: cannot touch '/data/acl_dir/acl_user1': Permission denied // The user of user1 has no write Permission on the acl_dir directory and cannot create files
- [User1 @ rhel6 ~] $ Exit
- [Root @ rhel6 data] # setfacl-m u: user1: rwx acl_dir // grant user1 the permission to read and write the acl_dir directory.
- [Root @ rhel6 data] # getfacl -- all-valid tive acl_dir/
- # File: acl_dir
- # Owner: root
- # Group: root
- User: rwx
- User: user1: rwx # valid tive: rwx
- Group: r-x # valid tive: r-x
- Mask: rwx
- Other: r-x
- [Root @ rhel6 data] # su-user1
- [User1 @ rhel6 ~] $ Touch/data/acl_dir/acl_user1 // the file can be created successfully.
- [User1 @ rhel6 ~] $ Ll-d/data/acl_dir // a "+" is added to the directory attribute of acl_dir"
- Drwxr-xr-x + 2 root 1024 Mar 24/data/acl_dir/
- Note: The executable permission must be granted to the directory; otherwise, the directory cannot be cd-ed.
-
- File:
- [Root @ rhel6 data] # touch acl_file
- [Root @ rhel6 data] # getfacl acl_file
- # File: acl_file
- # Owner: root
- # Group: root
- User: rw-
- Group: r --
- Other: r --
- [Root @ rhel6 data] # su-user1
- [User1 @ rhel6 ~] $ Echo "access test">/data/acl_file
- -Bash:/data/acl_file: Permission denied // user1 the user does not have the write Permission on the acl_file file.
- [Root @ rhel6 data] # setfacl-m u: user1: rw acl_file // grant user1 the read and write permissions on the acl_file file.
- [Root @ rhel6 data] # getfacl -- all-valid tive acl_file
- # File: acl_file
- # Owner: root
- # Group: root
- User: rw-
- User: user1: rw-# valid tive: rw-
- Group: r -- # valid tive: r --
- Mask: rw-
- Other: r --
- [Root @ rhel6 data] # su-user1
- [User1 @ rhel6 ~] $ Echo "access test">/data/acl_file // The acl_file file can be successfully written.
- [User1 @ rhel6 data] $ cat acl_file
- Access test
- [User1 @ rhel6 ~] $ Ll/data/
- Total 16
- Drwxrwxr-x + 2 root 1024 Mar 24 10:33 acl_dir
- -Rw-r -- + 1 root 12 Mar 24 10:39 acl_file
- Drwx ------. 2 root 12288 Mar 24 10:24 lost + found
- Mask:
- [Root @ rhel6 data] # setfacl-m: r acl_dir/
- [Root @ rhel6 data] # getfacl acl_dir/
- # File: acl_dir
- # Owner: root
- # Group: root
- User: rwx
- User: user1: rwx # valid tive: r --
- Group: r-x
- Mask: r --
- Other: r-x
- [Root @ rhel6 data] # su-user1
- [User1 @ rhel6 data] $ cd acl_dir/
- -Bash: cd: acl_dir/: Permission denied
-
- Because the user1 user does not have the x permission on this directory, this directory cannot be accessed even though we have granted the ACL settings of user1 user rwx.
- The final permission is controlled by the mask and must be within the mask. Otherwise, the permissions assigned to the mask are invalid.
- [Root @ rhel6 data] # mkdir dir
- [Root @ rhel6 data] # setfacl-d-m u: user1: rwx dir // make all files and directories under the dir/directory inherit the ACL settings of the dir/directory
- [Root @ rhel6 data] # getfacl dir/
- # File: dir/
- # Owner: root
- # Group: root
- User: rwx
- Group: r-x
- Other: r-x
- Default: user: rwx
- Default: user: user1: rwx
- Default: group: r-x
- Default: mask: rwx
- Default: other: r-x
- [Root @ rhel6 data] # touch dir/test
- [Root @ rhel6 data] # The user1 file created in the getfacl dir/test // dir directory also has the rwx permission.
- # File: dir/test
- # Owner: root
- # Group: root
- User: rw-
- User: user1: rwx # valid tive: rw-
- Group: r-x # valid tive: r --
- Mask: rw-
- Other: r --
- [Root @ rhel6 data] # setfacl-x u: user1 acl_file // remove the ACL settings of user1 in acl_file
- [Root @ rhel6 data] # getfacl acl_file
- # File: acl_file
- # Owner: root
- # Group: root
- User: rw-
- Group: r --
- Mask: r --
- Other: r --
- [Root @ rhel6 data] # ll acl_file
- -Rw-r -- + 1 root 12 Mar 24 acl_file // The "+" of the file attribute still exists.
- [Root @ rhel6 data] # setfacl-B acl_file // remove all ACL settings in acl_file
- [Root @ rhel6 data] # getfacl acl_file
- # File: acl_file
- # Owner: root
- # Group: root
- User: rw-
- Group: r --
- Other: r --
- [Root @ rhel6 data] # ll acl_file
- -Rw-r --. 1 root 12 Mar 24 acl_file // The "+" of the file attribute has been restored "."
- [Root @ rhel6 data] # getfacl dir/> acl. bak // export the ACL settings of the dir directory
- [Root @ rhel6 data] # setfacl -- set-file = acl. bak acl_dir // import ACL settings to the acl_dir directory
- [Root @ rhel6 data] # getfacl acl_dir/
- # File: acl_dir/
- # Owner: root
- # Group: root
- User: rwx
- Group: r-x
- Other: r-x
- Default: user: rwx
- Default: user: user1: rwx
- Default: group: r-x
- Default: mask: rwx
- Default: other: r-x