ACL for Advanced file permissions in Linux

Source: Internet
Author: User

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:

  1. [Root @ rhel6 ~] # Mount-o acl/dev/iscsi/sharedisk/data/
  2. [Root @ rhel6 ~] # Mount | grep sharedisk
  3. /Dev/mapper/iscsi-sharedisk on/data type ext4 (rw, acl)
  4. Note: If you use the tune2fs command to enable the partition ACL function, you cannot use the mount command.
  5. [Root @ rhel6 ~] # Tune2fs-o acl/dev/iscsi/sharedisk
  6. [Root @ rhel6 ~] # Tune2fs-l/dev/iscsi/sharedisk | grep-I "default mount option"
  7. Default mount options: acl
  8. [Root @ rhel6 ~] # Umount/data/
  9. [Root @ rhel6 ~] # Mount/dev/iscsi/sharedisk/data/
  10. [Root @ rhel6 ~] # Mount | grep sharedisk
  11. /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 ).
  1. [Root @ rhel6 data] # setfacl -- help
  2. Setfacl 2.2.49 -- set file access control lists
  3. Usage: setfacl [-bkndRLP] {-m |-M |-x |-X...} file...
  4. -M, -- modify = acl: changes the ACL rules of files or directories.
  5. -M, -- modify-file = file: Read ACL settings from a file and modify the ACL rules of the current file or directory as a template.
  6. -X, -- remove = acl: delete a specified ACL rule for a file or directory.
  7. -X, -- remove-file = file Read ACL settings from a file and delete the ACL rules of the current file or directory as a template
  8. -B, -- remove-all Delete all ACL rules of a file or directory
  9. -K, -- remove-default delete default ACL rules for files or directories
  10. -- Set = acl: sets the ACL rules for the current file.
  11. -- Set-file = file: Read ACL rules from a file to set ACL rules for the current file or directory
  12. -- The mask recalculates valid permissions, even if the ACL mask is explicitly specified
  13. -N, -- no-mask do not recalculate valid permissions. By default, setfacl recalculates the ACL mask, unless the mask is explicitly formulated.
  14. -D, -- default: Set the default ACL rules for the directory (only valid for the Directory)
  15. -R, -- recursive Processing
  16. -L, -- logical walk, follow symbolic links
  17. -P, -- physical walk, do not follow symbolic links
  18. -- Restore = file restore ACLs (inverse of 'getfacl-R ')
  19. -- 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.

 
  1. Directory:
  2. [Root @ rhel6 data] # mkdir acl_dir
  3. [Root @ rhel6 data] # ll-d acl_dir
  4. Drwxr-xr-x. 2 root 1024 Mar 24 :29 acl_dir/
  5. [Root @ rhel6 data] # getfacl acl_dir/
  6. # File: acl_dir
  7. # Owner: root "Basic Rules"
  8. # Group: root
  9. User: rwx
  10. Group: r-x "Default rule"
  11. Other: r-x
  12. [Root @ rhel6 data] # su-user1
  13. [User1 @ rhel6 ~] $ Touch/data/acl_dir/acl_user1
  14. 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
  15. [User1 @ rhel6 ~] $ Exit
  16. [Root @ rhel6 data] # setfacl-m u: user1: rwx acl_dir // grant user1 the permission to read and write the acl_dir directory.
  17. [Root @ rhel6 data] # getfacl -- all-valid tive acl_dir/
  18. # File: acl_dir
  19. # Owner: root
  20. # Group: root
  21. User: rwx
  22. User: user1: rwx # valid tive: rwx
  23. Group: r-x # valid tive: r-x
  24. Mask: rwx
  25. Other: r-x
  26. [Root @ rhel6 data] # su-user1
  27. [User1 @ rhel6 ~] $ Touch/data/acl_dir/acl_user1 // the file can be created successfully.
  28. [User1 @ rhel6 ~] $ Ll-d/data/acl_dir // a "+" is added to the directory attribute of acl_dir"
  29. Drwxr-xr-x + 2 root 1024 Mar 24/data/acl_dir/
  30. Note: The executable permission must be granted to the directory; otherwise, the directory cannot be cd-ed.
  31. File:
  32. [Root @ rhel6 data] # touch acl_file
  33. [Root @ rhel6 data] # getfacl acl_file
  34. # File: acl_file
  35. # Owner: root
  36. # Group: root
  37. User: rw-
  38. Group: r --
  39. Other: r --
  40. [Root @ rhel6 data] # su-user1
  41. [User1 @ rhel6 ~] $ Echo "access test">/data/acl_file
  42. -Bash:/data/acl_file: Permission denied // user1 the user does not have the write Permission on the acl_file file.
  43. [Root @ rhel6 data] # setfacl-m u: user1: rw acl_file // grant user1 the read and write permissions on the acl_file file.
  44. [Root @ rhel6 data] # getfacl -- all-valid tive acl_file
  45. # File: acl_file
  46. # Owner: root
  47. # Group: root
  48. User: rw-
  49. User: user1: rw-# valid tive: rw-
  50. Group: r -- # valid tive: r --
  51. Mask: rw-
  52. Other: r --
  53. [Root @ rhel6 data] # su-user1
  54. [User1 @ rhel6 ~] $ Echo "access test">/data/acl_file // The acl_file file can be successfully written.
  55. [User1 @ rhel6 data] $ cat acl_file
  56. Access test
  57. [User1 @ rhel6 ~] $ Ll/data/
  58. Total 16
  59. Drwxrwxr-x + 2 root 1024 Mar 24 10:33 acl_dir
  60. -Rw-r -- + 1 root 12 Mar 24 10:39 acl_file
  61. Drwx ------. 2 root 12288 Mar 24 10:24 lost + found
  62. Mask:
  63. [Root @ rhel6 data] # setfacl-m: r acl_dir/
  64. [Root @ rhel6 data] # getfacl acl_dir/
  65. # File: acl_dir
  66. # Owner: root
  67. # Group: root
  68. User: rwx
  69. User: user1: rwx # valid tive: r --
  70. Group: r-x
  71. Mask: r --
  72. Other: r-x
  73. [Root @ rhel6 data] # su-user1
  74. [User1 @ rhel6 data] $ cd acl_dir/
  75. -Bash: cd: acl_dir/: Permission denied
  76. 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.
  77. The final permission is controlled by the mask and must be within the mask. Otherwise, the permissions assigned to the mask are invalid.
 
  1. [Root @ rhel6 data] # mkdir dir
  2. [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
  3. [Root @ rhel6 data] # getfacl dir/
  4. # File: dir/
  5. # Owner: root
  6. # Group: root
  7. User: rwx
  8. Group: r-x
  9. Other: r-x
  10. Default: user: rwx
  11. Default: user: user1: rwx
  12. Default: group: r-x
  13. Default: mask: rwx
  14. Default: other: r-x
  15. [Root @ rhel6 data] # touch dir/test
  16. [Root @ rhel6 data] # The user1 file created in the getfacl dir/test // dir directory also has the rwx permission.
  17. # File: dir/test
  18. # Owner: root
  19. # Group: root
  20. User: rw-
  21. User: user1: rwx # valid tive: rw-
  22. Group: r-x # valid tive: r --
  23. Mask: rw-
  24. Other: r --
  25. [Root @ rhel6 data] # setfacl-x u: user1 acl_file // remove the ACL settings of user1 in acl_file
  26. [Root @ rhel6 data] # getfacl acl_file
  27. # File: acl_file
  28. # Owner: root
  29. # Group: root
  30. User: rw-
  31. Group: r --
  32. Mask: r --
  33. Other: r --
  34. [Root @ rhel6 data] # ll acl_file
  35. -Rw-r -- + 1 root 12 Mar 24 acl_file // The "+" of the file attribute still exists.
  36. [Root @ rhel6 data] # setfacl-B acl_file // remove all ACL settings in acl_file
  37. [Root @ rhel6 data] # getfacl acl_file
  38. # File: acl_file
  39. # Owner: root
  40. # Group: root
  41. User: rw-
  42. Group: r --
  43. Other: r --
  44. [Root @ rhel6 data] # ll acl_file
  45. -Rw-r --. 1 root 12 Mar 24 acl_file // The "+" of the file attribute has been restored "."
  46. [Root @ rhel6 data] # getfacl dir/> acl. bak // export the ACL settings of the dir directory
  47. [Root @ rhel6 data] # setfacl -- set-file = acl. bak acl_dir // import ACL settings to the acl_dir directory
  48. [Root @ rhel6 data] # getfacl acl_dir/
  49. # File: acl_dir/
  50. # Owner: root
  51. # Group: root
  52. User: rwx
  53. Group: r-x
  54. Other: r-x
  55. Default: user: rwx
  56. Default: user: user1: rwx
  57. Default: group: r-x
  58. Default: mask: rwx
  59. Default: other: r-x

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.