Managing File Attributes and Permissions

Hands-On Lab

 

Photo of Terrence Cox

Terrence Cox

Senior Vice President of Content

Length

01:00:00

Difficulty

Beginner

A firm understanding of how to manage file and directory attributes and permissions is one of the foundations of a being a successful system administrator. This activity will help you reinforce your understanding of key utilities like chmod along with how to apply the desired permissions to users, groups and 'everyone' on the system. Once you complete this learning activity, you will have a firm grasp on how permissions work across files and directories on your system.

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 Attributes and Permissions

Objectives

  1. Reset a directory's permissions to the following:
    • Everyone can access the directory
    • Everyone can read the files in the directory
    • No one can execute files in the directory
  2. Apply all of these permissions to all subdirectories recursively

Solution

Grant Access to the Directory

Change to the opt directory.

cd /opt

Next, open all of the directory's files and permissions with the following command:

ls -la

Let's try to access the myapp directory. Run the following command:

cd myapp/

We get a "Permission denied" message because permissions are currently restricted to the tkirk user. Let's change that now. Enter the following command:

sudo chmod 777 myapp

Then, enter your password when prompted.

Reopen the directory files and permissions using the ls -la command. Now let's try to open the directory again.

cd myapp

We can now open the directory.

Change the Directory Permissions

The next step is to give all users read and write permissions for this directory. However, we also need to make sure no one can execute anything. Let's start by removing execute permissions. Enter the following command:

sudo chmod -x -R *

Now let's give everyone read and write permissions.

sudo chmod 666 -R *

Reopen the directory files and permissions again.

ls -la

We can see that everyone now has read and write permissions.

Conclusion

Congratulations, you've successfully completed this lab!