EP8: File Permission & chmod Explained

🎯 What You’ll Learn

In this episode, we’ll break down:

  • What file permissions are πŸ”’

  • How to read them πŸ“–

  • How to change them using chmod πŸ› 

  • Real-world analogies that actually make sense πŸ‘·β€β™‚οΈ

All based on RHCSA exam objectives.


πŸ“¦ Why Permissions Matter?

Imagine Linux as an apartment building:

  • Every file or folder is like a room.

  • Each user is a tenant.

  • Permissions control who can enter, modify, or even see what's inside the room.

Without the correct permissions, users may:

  • Get denied access

  • Accidentally modify system files 😬

  • Or worse β€” cause security issues 🚨


🧾 Understanding the Permission Format

Run this command:

ls -l

You’ll see something like:

-rw-r--r--. 1 alice developers 1234 Jul 7 12:00 report.txt

Breakdown of -rw-r--r--:

Position

Meaning

-

File type (- for file, d for directory)

rw-

Owner's permission (read & write)

r--

Group’s permission (read-only)

r--

Others’ permission (read-only)

πŸ”‘ Permissions are always in this order:
User | Group | Others


🧠 Real-World Analogy

Permission

Symbol

Meaning

Real-World

Read

r

View content

Can read a document

Write

w

Modify content

Can edit a document

Execute

x

Run file as program

Can open/run a program or enter a room

For directories, x means:

  • You can enter (cd into) the directory

  • Without it, even if you can read files, you can’t enter the folder


πŸ›  How to Change Permissions: chmod

✳️ Symbolic Method

chmod [who]+/-[permission] filename

Who

Description

u

user (owner)

g

group

o

others

a

all (user + group + others)

βœ… Examples:

chmod u+x script.sh    # Add execute to user
chmod g-w file.txt     # Remove write from group
chmod o+r report.txt   # Add read for others
chmod a-x script.sh    # Remove execute for everyone

πŸ”’ Numeric Method (Octal)

Permissions also have numeric values:

Permission

Value

r

4

w

2

x

1

You add them up:

Symbol

Value

Meaning

rw-

6

4+2

r--

4

read only

rwx

7

full access

βœ… Example:

chmod 755 script.sh

Breakdown:

  • 7 = user β†’ rwx

  • 5 = group β†’ r-x

  • 5 = others β†’ r-x

Another one:

chmod 644 file.txt

Means:

  • User: read+write (6)

  • Group: read only (4)

  • Others: read only (4)


πŸ—‚ Bonus: Default Permissions & umask

Every time you create a file/folder, Linux assigns default permissions, which are affected by a value called umask.

βœ… Check umask:

umask

Common default is 0022, meaning:

  • Files default to 644

  • Directories default to 755

To permanently change umask, modify:

  • ~/.bashrc or /etc/bashrc for global changes

πŸ” Verify File Ownership

Use ls -l to check the owner and group:

-rw-r--r-- 1 alice developers 1234 Jul 7 12:00 file.txt

To change ownership:

sudo chown bob:designers file.txt

πŸ§ͺ Most Common RHCSA Scenarios

Scenario

Command

Make script executable

chmod +x script.sh

Secure private key file

chmod 600 id_rsa

Make directory accessible to all

chmod 755 /var/www/html

Remove all access for others

chmod o= file.txt


βœ… Summary / Key Takeaways

Command

Description

chmod

Change permission

chown

Change owner/group

ls -l

View permissions

umask

Show default permission mask

πŸ”‘ Remember:

  • Use symbolic method for readability

  • Use numeric (octal) for scripting or when you know exact values

  • File vs directory permissions behave slightly differently

  • Practice both methods for RHCSA exam


🎬 Final Words

Understanding permissions is essential for system security and file control. Once you grasp the concept, chmod becomes your daily command as a sysadmin!

Updated on