setfacl
Hosaac S. is the new Director of IT at Microsoft. He Learns that GNU/Linux Team is relatively weak of the use of the setfacl command on RHEL systems. Please give and explain 10 example uses of the setfacl command. Assume that username rondneyj is running all of the commands from his non-root account.
Here are 10 example uses of the setfacl
command on RHEL systems, along with the commands that username rondneyj
can use to achieve each use case:
- Allow multiple users to access a file or directory:
- setfacl -m u:user1:r,u:user2:rwx /path/to/file
- This command grants read (
r
) access touser1
and read, write, and execute (rwx
) access touser2
for the file or directory located at/path/to/file
.
- Allow a group to access a file or directory:
- setfacl -m g:group1:rx /path/to/file
- This command grants read and execute (
rx
) access togroup1
for the file or directory located at/path/to/file
.
- Grant a user or group full access to a file or directory:
- setfacl -m u:user1:rw,g:group1:rwx /path/to/file
- This command grants read, write (
rw
), and execute (rwx
) access togroup1
, and read and write access touser1
for the file or directory located at/path/to/file
.
- Remove a user or group's access to a file or directory:
- setfacl -x u:user1,g:group1 /path/to/file
- This command removes all permissions for
user1
andgroup1
from the file or directory located at/path/to/file
.
- Set a default ACL for a directory and its contents:
- setfacl -d -m g:group1:rwx /path/to/directory
- View a file or directory's ACL:
- getfacl /path/to/file
- This command displays the current ACL for the file or directory located at
/path/to/file
.
- Copy an ACL from one file to another:
- getfacl /path/to/source/file | setfacl --set-file=- /path/to/destination/file
- This command copies the ACL from
/path/to/source/file
to/path/to/destination/file
.
- Set a mask for a file or directory's ACL:
- setfacl -m m::rx /path/to/file
- This command sets a mask that limits the permissions of other users or groups in the ACL for the file or directory located at
/path/to/file
.
- Remove an ACL entry for a user or group:
- setfacl -x u:user1 /path/to/file
- This command removes the ACL entry for
user1
from the file or directory located at/path/to/file
.
This command sets an ACL that allows user1
to only execute (x
) the file located at /path/to/file
.
Note that for all of these examples, rondneyj
will need to have appropriate permissions to the file or directory in question in order to modify its ACL with the setfacl
command.