setfacl

Andre is a new employee at Red Hat who is struggling with copying ACLs from one file to another using getfacl and setfacl on a RHEL server. Please give him 5 examples to boost his confidence. First create an account for him (drummonda). Then give him sudo privileges. Then use his account to execute the commands. Create 5 files in Andre's home directory file01.txt through file05.txt. Use setfacl to remove Andre's write access to the five files. Then create 5 new files in the same directory, files06.txt to file10.txt and copy the ACLs from the first 5 files to the second five files. First show Andre the textbook correct way of completing the tasks, and then you can show him a shorter way of completing the tasks, if you wish.

Sure, here are 5 examples to help boost Andre's confidence with copying ACLs using getfacl and setfacl on a RHEL server:

  1. Create a new account for Andre and give him sudo privileges:
    • sudo useradd -m -s /bin/bash drummonda
      sudo passwd drummonda
      sudo usermod -aG wheel drummonda
    • These commands create a new user account for Andre with a home directory, and set his shell to Bash. The second command sets a password for Andre. The third command adds Andre to the wheel group, which grants him sudo privileges.
  2. Create 5 files in Andre's home directory and remove his write access using setfacl:
    • touch /home/drummonda/file01.txt /home/drummonda/file02.txt /home/drummonda/file03.txt /home/drummonda/file04.txt /home/drummonda/file05.txt
    • setfacl -m u:drummonda:r-x /home/drummonda/file01.txt /home/drummonda/file02.txt /home/drummonda/file03.txt /home/drummonda/file04.txt /home/drummonda/file05.txt
    • These commands create 5 files in Andre's home directory and remove his write (-w) access to the files while retaining read (-r) and execute (-x) access.
  3. Create 5 new files in Andre's home directory and copy ACLs from the first 5 files using getfacl and setfacl:
    • touch /home/drummonda/file06.txt /home/drummonda/file07.txt /home/drummonda/file08.txt /home/drummonda/file09.txt /home/drummonda/file10.txt
    • getfacl /home/drummonda/file01.txt | setfacl --set-file=- /home/drummonda/file06.txt
    • getfacl /home/drummonda/file02.txt | setfacl --set-file=- /home/drummonda/file07.txt
    • getfacl /home/drummonda/file03.txt | setfacl --set-file=- /home/drummonda/file08.txt
    • getfacl /home/drummonda/file04.txt | setfacl --set-file=- /home/drummonda/file09.txt
    • getfacl /home/drummonda/file05.txt | setfacl --set-file=- /home/drummonda/file10.txt
    • These commands create 5 new files in Andre's home directory and copy the ACLs from the first 5 files using getfacl and setfacl.
  4. Shorter way to copy ACLs using a loop:
    • for i in {1..5}; do getfacl /home/drummonda/file0$i.txt | setfacl --set-file=- /home/drummonda/file$(($i+5)).txt; done
    • This command uses a loop to iterate through the first 5 files and copy their ACLs to the corresponding numbered files with a +5 suffix.
  5. Verify the ACLs of the second 5 files using getfacl:
    • getfacl /home/drummonda/file06.txt /home/drummonda/file07.txt /home/drummonda/file08.txt /home/drummonda/file09.txt /home/drummonda/file10.txt

This command verifies the ACLs of the second 5 files to confirm that they have been copied correctly.

After running these commands, Andre should have 10 files in his home directory.

 

You should also read:

setfacl

Charlie "Bird" Parker is a genius-level jazz alto saxophonist. He has just read a book about setfacl, in fact he memorized the entire…

setfacl

Charles Parker Jr. is a genius with an IQ somewhere north of 150. He leads his jazz quintet by night (in which he…

setfacl

Demea is a Master Linux Sysadmin at Red Hat. She has a multi-part task in from of her. Please list all of the…

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…