Managing File Permissions in Linux Using chmod

Managing File Permissions in Linux Using chmod

in

Managing File Permissions in Linux Using chmod

Practical experience with the Google Cybersecurity Certificate

Project Description

In this task, I examined the existing permissions on the file system within the projects directory and determined whether they matched the intended authorization settings.

If the permissions didn’t match the expected configuration, I modified them to authorize the appropriate users and remove any unauthorized access.


Checking File and Directory Details

To check the current file permissions in the projects directory, I used the following command:

ls -la
  • The ls command lists the contents of the directory — including project files and a folder called drafts.
  • The -l option displays detailed information such as ownership and permissions.
  • The -a option shows hidden files (those starting with a dot .).

1_apCksZ7DBbuYq0c5XnqMZQ.jpg

In this case, I discovered a hidden file named .project_x.txt.


Understanding the Permissions String

Each line of the ls -l output starts with a string indicating the file type and its permissions. Here’s how to read it:

The first character indicates the type:

  • - for a file
  • d for a directory

The next nine characters are divided into three groups:

  • The first group shows permissions for the user (owner)
  • The second group is for the group
  • The third group is for others (everyone else)

Permission Characters Meaning:

  • r Read permission
  • w Write permission
  • x Execute permission
  • - Permission not granted

Changing File Permissions

It was determined that other users should not have write permissions.

One file, project_k.txt, incorrectly allowed write access to others.

1_El1u1tICIX6P-Ok3e4oeuA.jpg

To fix this, I ran:

chmod o-w project_k.txt
  • chmod modifies permissions.
  • o-w removes write permissions from “others”.
  • project_k.txt is the target file.

To confirm the changes, I ran ls -la again and verified that the write permission was removed.


Changing Permissions on a Hidden File

The file .project_x.txt was archived by the research team as a hidden file. It was requested that no one should have write permissions, and the user and group should have read permissions.

1_FK7NsMsplwfInyBsQPdp1Q.jpg

To achieve this, I ran:

chmod u-w,g-w,g+r .project_x.txt

This command:

  • Removes write permission from the user (u-w)
  • Removes write permission from the group (g-w)
  • Adds read permission to the group (g+r)

Changing Directory Permissions

The drafts folder should only be accessible by the researcher2 user. Specifically, only researcher2 should have execute permissions.

1_bsy5ANB0b_dBOyKpQpCRlg.jpg

  • The researcher2 user already had execute permissions, so no changes were needed there.
  • However, the group also had execute permissions, which needed to be removed.

To update group permissions:

chmod g-x drafts

This removed the execute permission for the group, restricting access to the directory contents and not allowing to execute files within.


Summary

This task involved analyzing and modifying file and directory permissions to match the organization’s access control policies.

Key Takeaways:

  • The chmod command was used to modify user, group, and other permissions.
  • The ls -la command helped verify permissions before and after changes.
  • Understanding permission strings is crucial for correctly applying access controls in Linux environments.