Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:access-control-lists [2017/10/27 17:12] – created michaellinux:access-control-lists [2019/03/07 13:51] (current) michael
Line 13: Line 13:
 ''Note the **+** sign at the end of the permissions. This confirms that the file has an ACL attached to it.'' ''Note the **+** sign at the end of the permissions. This confirms that the file has an ACL attached to it.''
  
----- 
  
 ===== Viewing ACLs ===== ===== Viewing ACLs =====
  
  
-----+<WRAP center box 100%> 
 + 
 +''To display details ACL information of a file use the getfacl command.'' 
 +<code> 
 +# getfacl /tmp/test 
 +</code> 
 + 
 +<sxh plain; gutter: false;> 
 +# file: test 
 +# owner: root 
 +# group: root 
 +user::rw- 
 +user:john:rw- 
 +user:sam:rwx 
 +group::r-- 
 +mask::rwx 
 +other:--- 
 +</sxh> 
 +</WRAP> 
 + 
 +Notice the 3 different user: lines. The first line lists the standard file permissions of the owner of the file. The 2 other user permissions are the individual permission for the user john and sam. The mask field here only applies to the additional permissions we have given to the user and groups. If the mask is set to rwx the read, write and execute permissions will be granted to additional user/groups. If the mask is set to r-x, the write permission will not be granted to additional user/groups.In general, ''<wrap em>DO NOT</wrap> set mask to anything other **than rwx**. **The mask value does not affect the standard UNIX user/group/others permissions.**'' 
 + 
 + 
 +<WRAP center box 100%> 
 +**File with no ACLs** 
 + 
 +''If you run the getfacl command on a file with no ACLs the additional “user:” lines and “mask” line will not be shown and standard file permissions will be shown.'' 
 +<code> 
 +# getfacl test 
 +</code> 
 + 
 +<sxh plain; gutter: false;> 
 +# file: test 
 +# owner: root 
 +# group: root 
 +user::rw- 
 +group::r-- 
 +other::r-- 
 +</sxh> 
 +</WRAP>
  
  
 ===== Creating and Managing FACLs ===== ===== Creating and Managing FACLs =====
 +The ''**setfacl**'' command is used to set ACL on the given file. To give a rw access to user john on the file /tmp/test :
  
 +<code># setfacl -m u:john:rw /tmp/test</code>
  
-----+  * The **-m** option tells setfacl to modify ACLs on the file(s) mentioned in command line. Instead of user john we can have a group to have a specific permission on the file : <code># setfacl -m g:accounts:rw /tmp/test</code> 
 +  * FACLs for multiple user and groups can also be set with single command : <code># setfacl -m u:john:rw,g:accounts:rwx /tmp/test</code>
  
  
 ===== Default FACLs on directories ===== ===== Default FACLs on directories =====
 +Default ACLs are only created on directories. When you set default ACLs on directories, any files created within that directory will also have that default FACL assigned automatically.
  
 +**To create a default FACL on a directory:**
  
-----+<code># setfacl -m default:u:john:rw /accounts</code>
  
 +<WRAP center box 100%>
 +<code>
 +# getfacl accounts/
 +</code>
 +
 +<sxh plain; gutter: false;>
 +# file: accounts/
 +# owner: root
 +# group: root
 +user::rwx
 +group::r-x
 +other::r-x
 +default:user::rwx
 +default:user:john:rw-
 +default:group::r-x
 +default:mask::rwx
 +default:other::r-x
 +</sxh>
 +</WRAP>
 +
 +''//Now create a new file in the accounts directory and list the FACL on the file ://''
 +
 +<WRAP center box 100%>
 +<code>
 +# touch /accounts/test
 +</code>
 +
 +<sxh plain; gutter: false;>
 +# getfacl test
 +# file: test
 +# owner: root
 +# group: root
 +user::rw-
 +user:john:rw-
 +group::r-x #effective:r--
 +mask::rw-
 +other::r--
 +</sxh>
 +</WRAP>
  
  
 ===== Removing FACLs ===== ===== Removing FACLs =====
  
 +''To remove FACL, use the setfacl command with -x option :''
  
 +<code># setfacl -x u:john /tmp/test</code>
  
 +''**The above command removes the ACL for the user john on the file /tmp/test.** The ACLs for other user/groups if any remains unaffected.''
 +
 +''<wrap em>To remove all ACLs associated to a file use the -b option with setfacl :</wrap>''
 +
 +<code># setfacl -b /tmp/test</code>
  
----- 
  
 ===== Backing up the FACLs ===== ===== Backing up the FACLs =====
  
-----+Many a times, the backup software may not copy the metadata related to the FACL on the files. In that case you may want to backup the FACL information on the files. Now, the FACL on all the files in a directory (including all sub directories) can be copied in a single file. 
 + 
 +<code># cd /accounts 
 +# getfacl -R * > accounts_facl        ( --> recursive )</code> 
  
 ===== Restoring the FACLs ===== ===== Restoring the FACLs =====
  
 +When you restore the files in /accounts directory, you would have to restore the FACLs associated with the files in that direcotry. TO do that use the FACL backup file accounts_facl along with the –restore option :
  
 +<code># setfacl --restore=accounts_facl</code>
  
 ---- ----
  
 Quelle: https://www.thegeekdiary.com/unix-linux-access-control-lists-acls-basics/ Quelle: https://www.thegeekdiary.com/unix-linux-access-control-lists-acls-basics/
  • linux/access-control-lists.1509117166.txt.gz
  • Last modified: 2017/10/27 17:12
  • by michael