Linux Permission Modifying

LinuxLinuxBeginner
Practice Now

Introduction

In a medieval city nestled amidst rolling hills and thriving markets, word has spread of the arrival of a traveling minstrel — a poet with tales that echo through the halls of time. The minstrel carries with them an ancient tome, filled with songs and stories of old, intended to be shared with all, yet guarded against the night's darkness when only the chosen few gather to hear whispers of wisdom and courage.

The minstrel seeks an apprentice in this bustling city. One who can grasp the art of safeguarding the tome's knowledge by day while making it accessible to the eager ears by night. To prove their worth, the apprentice must master the craft of modifying permissions, using the enchanted chmod command within the realm of Linux.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicFileOperationsGroup -.-> linux/chmod("`Permission Modifying`") subgraph Lab Skills linux/chmod -.-> lab-271241{{"`Linux Permission Modifying`"}} end

Creating the Minstrel's Tome

In this step, you will create the ancient tome that the minstrel intends to share with the city's inhabitants. Begin by crafting the tome as a text file and setting its initial permissions to reflect that only the minstrel (the file owner) can read and write to the tome while preventing others from viewing its contents.

Navigate to the working directory:

cd ~/project

Create the tome file named ancient_tome.txt:

touch ancient_tome.txt

Set the initial permissions:

chmod 600 ancient_tome.txt

This command modifies the permissions of ancient_tome.txt, granting read and write access to the owner, with neither the group nor others having any access.

See here for a detailed explanation:

chmod: is a Unix/Linux command used to change the permissions of files or directories.

600: This is the permission mode, which controls the permissions of files.

  • The first number 6 represents the permissions of the file owner (user).
  • The second number 0 represents the permissions of the group to which the file belongs (Group).
  • The third number 0 represents the permissions of other users (Other).

Description of the permission numbers:

  • 4 means read permission (Read), corresponding to the number r.
  • 2 means write permission, corresponding to the number w.
  • 1 means execute permission, corresponding to the number x.

The meaning of chmod 600:

  • 6 means that the file owner has read and write permission.
  • 0 means that the group to which the file belongs and other users have no permissions.

So only the file owner can read and write ancient_tome.txt, while other users have no permissions.

Verify the permissions:

ls -l ancient_tome.txt

The output should resemble:

-rw------- 1 labex labex 0 date time ancient_tome.txt

Sharing the Tome with the Chosen Few

Next, you will simulate the minstrel's desire to share the tome with a select group of people by night. You will modify the tome's permissions to allow group members to read its contents while ensuring others remain oblivious to the secrets penned within.

Add a group called chosen_few:

sudo groupadd chosen_few

Assign the tome to the chosen_few group:

sudo chown labex:chosen_few ancient_tome.txt

Modify the tome's permissions to allow group read access:

chmod 640 ancient_tome.txt

This grants read access to the group and retains read and write access for the owner.

Verify the new permissions:

ls -l ancient_tome.txt

The output should now look like this:

-rw-r----- 1 labex chosen_few 0 date time ancient_tome.txt

Summary

In this lab, we ventured through the medieval lens of file permissions in Linux. We stepped into the shoes of an apprentice learning the arcane chmod command, witnessed the creation of the ancient_tome.txt, and skillfully modified its permissions. The tale unfolded as we protected the tome from prying eyes while selectively sharing its knowledge with the chosen few.

Your command over permissions has now solidified — a skill that is foundational yet powerful, like the words of the minstrel's songs. May your journey through Linux continue to be as enlightening as the tales bound within the minstrel’s tome.

Other Linux Tutorials you may like