Skip to main content

Managing File Ownership and Permissions

Hands-On Lab

 

Photo of Michael Christian

Michael Christian

Course Development Director in Content

Length

01:45:00

Difficulty

Beginner

In this hands-on lab, we will practice managing Linux file and directory ownership and permissions. Having a solid understanding of ownership and permissions is a fundamental skill for Linux systems administration.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Managing File Ownership and Permissions

Introduction

In this hands-on lab, we will practice managing Linux file and directory ownership and permissions. Having a solid understanding of ownership and permissions is a fundamental skill for Linux systems administration.

Connecting to the Lab

  1. Open your terminal application, and run the following command (remember to replace PUBLIC_IP with the public IP you were provided on the lab instructions page):
    ssh cloud_user@PUBLIC_IP
  2. Enter yes at the prompt.
  3. Enter your cloud_user password at the prompt.

Lock Bill's, Susan's, and Juan’s Accounts

  1. List the current working directory.
    pwd
  2. List the existing home directories.
    ll /home/
  3. Lock Bill's, Susan's, and Juan's accounts.
    for i in bill susan juan; do sudo passwd -l $i; done
  4. Enter your cloud_user password at the prompt.

Create Accounts for Nancy, Greg, and Jeremy

  1. Run the following command:
    for i in nancy greg jeremy; do sudo useradd -m $i; done

Remove Bill as a User and Transfer Ownership of his Home Directory

  1. View Jason's permissions.
    id jason
  2. Remove the user bill.
    sudo userdel bill
  3. List the existing home directories.
    ll /home/
  4. Change the ownership of Bill's home directory (recursively) to the user nancy and the group jason.
    sudo chown -R nancy:jason /home/bill
  5. Verify that this was successful.
    ll /home/
  6. Change the mode of the directory to grant read and execute permissions to the group.
    sudo chmod g+rx /home/bill
  7. View the permissions for the files in Bill's home directory.
    sudo ls -l /home/bill

Remove Susan as a User and Transfer Ownership of her Home Directory

  1. Remove the user susan.
    sudo userdel susan
  2. Change the ownership of Susan's home directory (recursively) to the user greg and the group jason.
    sudo chown -R greg:jason /home/susan
  3. Change the mode of the directory to grant read and execute permissions to the group.
    sudo chmod g+rx /home/susan
  4. Verify that this was successful.
    ll /home

Remove Juan as a User and Transfer Ownership of His Home Directory

  1. View Sally's permissions.
    id sally
  2. Remove the user juan.
    sudo userdel juan
  3. Change the ownership of Juan's home directory (recursively) to the user jeremy and the group sally.
    sudo chown -R jeremy:sally /home/juan
  4. Change the mode of the directory to grant read and execute permissions to the group.
    sudo chmod g+rx /home/juan
  5. Verify that this was successful.
    ll /home/
  6. Become the user nancy.
    sudo su - nancy
  7. List the current working directory.
    pwd
  8. Change to the /home/bill directory.
    cd /home/bill
  9. List the contents of the directory to verify that nancy has read permissions for the directory.
    ll
  10. Add a new line to bill_files_1 to verify that the user nancy has write permissions for the directory.
    echo "a new line" >> bill_files_1
  11. Verify that this was successful.
    tail -n1 bill_files_1

Conclusion

Congratulations, you've successfully completed this hands-on lab!