DEV Community

LaTerral Williams
LaTerral Williams

Posted on

🦊 "Believe It!" - Mastering Linux File Permissions with Naruto 🍥

In the shinobi world, (I don't know this first-hand, this is only for presentation) not everyone can access the Hokage's scrolls or enter top-secret villages.

Similarly, in the Linux world, not all users can read, write, and execute every file. That's where Linux permissions and the legendary change commands come in:

  • chmod – Change a file’s jutsu access level (permissions)
  • chown – Change the ninja who controls the file (owner)
  • chgrp – Change the clan responsible for it (group)

Today, we'll walk through real-world examples of these commands, with Naruto and his pals.

Image description


🗂️ Table of Contents


🍃 Setup: Hidden Leaf Village Training Grounds

Let’s create a playground for our ninjas to train in. Open your terminal and run:

mkdir -p ~/ninja_village/mission_scrolls
cd ~/ninja_village
touch naruto.txt sasuke.txt sakura.txt
Enter fullscreen mode Exit fullscreen mode

Image description

These are the shinobi profiles. Inside mission_scrolls, we’ll keep top-secret files. We'll take a look at this later.


🥷 chown: Who Owns the File?

In the ninja world, being assigned to a mission means having ownership of that task. Similarly, chown gives control of a file to a specific user.

Let’s say Kakashi-sensei gives Naruto his own scroll.

sudo chown naruto naruto.txt
Enter fullscreen mode Exit fullscreen mode

Image description

Hmmm...What did we miss?

If you created naruto as a user before using chown or recognized that the cmd would not work, I want to encourage you to keep learn! We are actually grasping the concepts!


Create naruto as a user and try the chown cmd again...

Now Naruto is the owner of naruto.txt.

Check ownership with:

ls -l
Enter fullscreen mode Exit fullscreen mode

Image description


👪 chgrp: Clan Control

Sometimes missions are assigned to a clan, like the Uchiha or Hyuga. chgrp lets us assign a file to a group.

Let’s put Sasuke's file under the Uchiha clan’s control:

sudo chgrp uchiha sasuke.txt
Enter fullscreen mode Exit fullscreen mode

You can view the group with:

ls -l
Enter fullscreen mode Exit fullscreen mode

Make sure the group uchiha exists:

sudo groupadd uchiha
Enter fullscreen mode Exit fullscreen mode

Image description


🔐 chmod: Jutsu Access Levels

Now comes the fun part... permissions! Think of these as who can read, write, or execute (perform jutsu) on a file.

If Naruto’s file should only be read by him and no one else:

sudo chmod 600 naruto.txt
Enter fullscreen mode Exit fullscreen mode

To make Sakura’s file world-readable:

sudo chmod 644 sakura.txt
Enter fullscreen mode Exit fullscreen mode

If Sasuke wants to execute a mysterious script:

sudo chmod 755 sasuke.txt
Enter fullscreen mode Exit fullscreen mode

Image description


🔢 Understanding Numeric Permissions

Linux permission numbers are calculated using:

  • 4 = Read (r)
  • 2 = Write (w)
  • 1 = Execute (x)

Add them together to get the level of access:

Number Meaning Binary Example Description
7 rwx (full) 111 Read, write, and execute
6 rw- 110 Read and write only
5 r-x 101 Read and execute only
4 r-- 100 Read only
3 -wx 011 Write and execute
2 -w- 010 Write only
1 --x 001 Execute only
0 --- 000 No permissions

So chmod 755 means:

  • Owner = 7 = rwx
  • Group = 5 = r-x
  • Others = 5 = r-x

🔁 Symbolic Notation Examples (u, g, o + - =)

Instead of using numbers, you can also use symbolic characters:

📥 Add permissions (+)

Give Naruto’s file execute power (so he can run his own shadow clone jutsu):

sudo chmod u+x naruto.txt
Enter fullscreen mode Exit fullscreen mode

📤 Remove permissions (-)

Prevent others from reading Sakura’s file:

sudo chmod o-r sakura.txt
Enter fullscreen mode Exit fullscreen mode

🟰 Set exact permissions (=)

Only allow the group (Team 7) to read and write Sasuke’s file—nothing else:

sudo chmod g=rw sasuke.txt
Enter fullscreen mode Exit fullscreen mode

Image description


🈳 Understanding Symbolic Permissions

Symbolic permissions allow you to modify file access in a more human-readable way using characters and symbols instead of numbers.

🔑 Syntax of Symbolic Mode:

chmod [who][operator][permissions] filename
Enter fullscreen mode Exit fullscreen mode

👥 [who] – Who are you assigning permissions to?

Symbol Who it affects Meaning
u User The owner of the file
g Group The group assigned to file
o Others All other users
a All Equivalent to u, g, and o

⚙️ [operator] – What are you doing?

Symbol Action Meaning
+ Add Add specified permissions
- Remove Remove specified permissions
= Assign exactly Set only the specified permissions (removes others)

📜 [permissions] – What type of access?

Symbol Permission Type Description
r Read View the contents of a file
w Write Modify or delete a file
x Execute Run the file as a program/script

🧪 Example Combinations:

Command Meaning
chmod u+x file.txt Add execute permission for the user
chmod g-w file.txt Remove write permission from the group
chmod o=r file.txt Set others to have only read permission
chmod a+rw file.txt Give read and write permission to user, group, and others
chmod ug=rw file.txt Set user and group to have read/write, and remove other permissions
chmod o= file.txt Remove all permissions from others

🧪 Bonus: Hidden Jutsu for Directory Permissions

Inside mission_scrolls, let’s add a secret mission file and set special permissions.

touch mission_scrolls/s-rank.txt
sudo chmod 700 mission_scrolls
sudo chmod 600 mission_scrolls/s-rank.txt
Enter fullscreen mode Exit fullscreen mode

Only the Hokage (root user) can access this!

Image description

Image description


🧭 Summary Table: Ninja Commands

Command Meaning Naruto Analogy
chown Change file owner Assign mission to a specific ninja
chgrp Change group ownership Assign mission to a clan
chmod (numeric) Set permissions with numbers Broad mission rank setting
chmod (symbolic) Add/remove exact permissions Grant or revoke access like chakra seals

🍜 Final Words from Ichiraku Ramen

Managing file permissions is like managing missions in the ninja world, you need the right person (or group) with the right access. Give too much access, and you risk a rogue ninja (or hacker) sabotaging the mission. Too little, and the mission might fail before it starts.

So next time you're setting permissions, channel your inner Hokage, and do it with precision.

“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way!” – Naruto Uzumaki


💬 Let’s Connect

Top comments (0)