Linux Hands-On Lab - Managing File Attributes and Permissions

Linux Hands-On Lab - Managing File Attributes and Permissions

Linux Learning Path for Cloud and DevOps Engineers

📝Introduction

This post 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.

These are the objectives of this lab:

  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

📝Log in to the AWS Management Console

Using your credentials, make sure you're using the right Region. In my case, I am using AWS as my cloud provider and chose us-east-1. However, you can choose any cloud provider and create your Linux Server VM (I am using a CentOS 7 distro) for this hands-on lab.

📌Note: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.

You can use link1 and link2 for it.

📝Grant Access to the Directory

To understand better how the permissions on Linux work, you can go through my other post about this topic on this link.

📌Note: The settings I used in this lab are illustrative, and you can apply them to your preference.

Change to any directory.

cd /<dir>

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

ls -la

Let's try to access a directory as per your choice. Run the following command:

cd <dir>

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

sudo chmod 777 <dir>

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 <dir>

We can now open the directory. So, we have changed the permissions on the /opt/myapp directory so that everyone can change to and read the files within that 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 -f -x -R *

Now let's give everyone read and write permissions.

📌Note: This would also remove the execute permissions we did in the previous step, but we wanted to show how to do that explicitly.

sudo chmod 666 -f -R *

List the directory files and permissions again.

ls -la

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

📌Note: For users to be able to navigate into directories, the directories must be set as executable.

You can do this with:

sudo find <dir> -type d -exec chmod o+x {} \;

List the directory files and permissions again.

ls -la

📌Note - At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged if you used a Cloud Provider to provision them.

Congratulations — you have completed this hands-on lab covering the basics of applying the desired permissions to users, groups and 'everyone' in Linux.

Thank you for reading. I hope you understood and learned something helpful from my blog.

Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza