The setfacl command is used to change the permissions associated with the ACL of a file or directory. The setfacl command has several options, some of the most common of which are described in the following table.
Option | Description |
---|---|
-R | Recursively set ACL options for directories and their contents. |
-s | Set the ACL of an object, replacing any existing ACL. |
-m | Modify the existing ACL of an object. |
-x | Remove entries from an existing ACL. |
-b | Remove all ACL entries (not including the standard permissions). |
Syntax
The syntax of the setfacl command is:
# setfacl [-bR] [-mx {acl_spec}] {file/directory names}
The following is an example of modifying the ACL on a directory where the user http is given read access:
setfacl -m u:http:r-- /home/directory
If you encounter below error while executing the setfacl command:
setfacl: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install acl |
Ubuntu | apt-get install acl |
Alpine | apk add acl |
Arch Linux | pacman -S acl |
Kali Linux | apt-get install acl |
CentOS | yum install acl |
Fedora | dnf install acl |
Raspbian | apt-get install acl |
Removing ACL
The setfacl command is also used with the -x option to remove the applied ACL for any user or group. The only difference when removing ACL from setting ACL is that we don’t specify the permission while removing. The following example illustrates the usage of the setfacl command to remove the ACL applied to a file named as file1 for the user geel and the group lab:
$ setfacl -x u:geek,g:lab file1
To remove all ACLs from a file or directory, we can use the -b option, as shown in the following command:
$ setfacl -b file1
setacl Command Examples
1. Modify ACL of a file for user with read and write access:
# setfacl -m u:username:rw file
2. Modify default ACL of a file for all users:
# setfacl -d -m u::rw file
3. Remove ACL of a file for a user:
# setfacl -x u:username file
4. Remove all ACL entries of a file:
# setfacl -b file