1. What is chmod?

chmod means "change mode". It is used to change file permissions — determining who can read, write, or execute a file.

3 Types of Users

  • Owner (u): Person who created the file.
  • Group (g): Users in same group.
  • Others (o): Everyone else.

3 Permissions

  • r = Read (View file)
  • w = Write (Edit/Delete)
  • x = Execute (Run script)

2. The Numbers Game (4-2-1)

Permissions use simple math. Memorize this:

Permission Value
Read (r) 4
Write (w) 2
Execute (x) 1

Example: chmod 755 file

7 (Owner) = 4+2+1 (Read + Write + Execute)

5 (Group) = 4+1 (Read + Execute)

5 (Others) = 4+1 (Read + Execute)

3. Hands-On Practice

Step 1: Create a File

nano test.sh # Add inside: echo "Hello Students" # Save and Exit (Ctrl+X, Y, Enter)

Step 2: Check Permissions

ls -l test.sh # Output example: -rw-r--r-- 1 user user test.sh

4. Common Permission Sets

chmod 777

rwxrwxrwx

Everyone can do everything.

⚠ UNSAFE!

chmod 755

rwxr-xr-x

Owner: Full control.

Others: Read & Run.

Best for Scripts.

chmod 644

rw-r--r--

Owner: Edit.

Others: Read only.

Best for Docs.

5. Fixing "Permission Denied"

The Problem

If you try to run a script without 'x' permission:

./test.sh

❌ Permission denied

The Fix

Add Execute permission (+x):

chmod +x test.sh

Now run it:

./test.sh

✅ Hello Students

🧪 Mini Exercise

1. Create practice.sh having echo "Test" inside.

2. Run the following and answer: Which one blocks execution?

chmod 644 practice.sh ./practice.sh # ? chmod 755 practice.sh ./practice.sh # ? chmod 700 practice.sh ./practice.sh # ?