Skip to content
Snippets Groups Projects
standard-file-acl.md 2.58 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jan Siwiec's avatar
    Jan Siwiec committed
    # Standard File ACL
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    Access control list (ACL) provides an additional, more flexible permission mechanism for file systems. It is designed to assist with UNIX file permissions. ACL allows you to give permissions for any user or group to any disk resource.
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ## Show ACL
    
    
    To show permissions, use:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # getfacl <file/dir>
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```
    
    ### Examples
    
    Set all permissions for user John to file named abc:
    
    ```code
    # setfacl -m "u:John:rwx" abc
    ```
    
    
    Check permissions:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # getfacl abc
    # file: abc
    # owner: someone
    # group: someone
    user::rw-
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    user:John:rwx
    
    group::r--
    mask::rwx
    other::r--
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```
    
    Change permissions for user John:
    
    ```code
    # setfacl -m "u:John:r-x" abc
    ```
    
    
    Check permissions:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # getfacl abc
    # file: abc
    # owner: someone
    # group: someone
    user::rw-
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    user:John:r-x
    
    group::r--
    mask::r-x
    other::r--
    
    Remove all ACL entries:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -b abc
    
    Check permissions:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # getfacl abc
    # file: abc
    # owner: someone
    # group: someone
    user::rw-
    group::r--
    other::r--
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ## Output of LS Command
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    
    You will notice that there is an ACL for a given file because it will exhibit `+`  after its Unix permissions in the output of `ls -l`.
    
    ```code
    
    $ ls -l /dev/audio
    crw-rw----+ 1 root audio 14, 4 nov.   9 12:49 /dev/audio
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```
    
    ```code
    
    $ getfacl /dev/audio
    getfacl: Removing leading '/' from absolute path names
    # file: dev/audio
    # owner: root
    # group: audio
    user::rw-
    user:solstice:rw-
    group::rw-
    mask::rw-
    other::---
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ## Modify ACL
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    The ACL can be modified using the `setfacl` command.
    
    You can list file/directory permission changes without modifying the permissions (i.e. dry-run) by appending the `--test` flag.
    To apply operations to all files and directories recursively, append the `-R/--recursive` argument.
    
    To set permissions for a user (user is either the user name or ID):
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -m "u:user:permissions" <file/dir>
    
    To set permissions for a group (group is either the group name or ID):
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -m "g:group:permissions" <file/dir>
    
    To set permissions for others:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -m "other:permissions" <file/dir>
    
    To allow all newly created files or directories to inherit entries from the parent directory (this will not affect files which will be copied into the directory):
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -dm "entry" <dir>
    
    To remove a specific entry:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -x "entry" <file/dir>
    
    To remove the default entries:
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -k <file/dir>
    
    To remove all entries (entries of the owner, group and others are retained):
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    ```code
    
    # setfacl -b <file/dir>
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    Source: [wiki.archlinux.org][1]
    
    
    Jan Siwiec's avatar
    Jan Siwiec committed
    [1]: https://wiki.archlinux.org/title/Access_Control_Lists