Chapter 47: Bash Modify (chmod)

Bash Modify (chmod)

chmod = change mode

This is the most important command for controlling file & folder permissions in Linux/Bash. After we learned what permissions look like (ls -l showing rwxr-xr-x), and who owns what (ownership with chown), now we learn how to actually change those rwx rules whenever we want.

Without chmod, scripts won’t run, folders can’t be entered, files can’t be edited, web servers can’t serve pages — basically everything breaks. So let’s treat chmod like your magic wand — you’ll use it every single day once you get comfortable.

Two Ways to Use chmod (Both Are Important)

  1. Symbolic mode → using letters like u+x, g-w, a=r (easier to read & remember for beginners)
  2. Numeric (octal) mode → using numbers like 755, 644, 700 (faster once you memorize, very common in scripts & tutorials)

We’ll learn both — most people start with symbolic, then switch to numeric.

First: Quick Reminder of Permission Letters & Numbers

Permission For files For folders Letter Octal value
read Can view/cat/open Can ls (see contents) r 4
write Can edit/change/delete Can create/delete/rename inside w 2
execute Can run as script/program Can cd into the folder x 1

Three groups:

  • u = user/owner
  • g = group
  • o = others (everyone else)
  • a = all (u+g+o)

1. Symbolic Mode (Letters – Very Human-Friendly)

Basic pattern:

Bash
  • who: u, g, o, a
  • operator: + (add), – (remove), = (set exactly)
  • permissions: r, w, x (or combinations)

Examples you’ll use every day:

Bash

Real quick practice:

Bash

2. Numeric (Octal) Mode – The Fast & Professional Way

Each group gets a number 0–7:

  • 7 = rwx (4+2+1)
  • 6 = rw- (4+2)
  • 5 = r-x (4+1)
  • 4 = r–
  • 0 = —

Order: owner → group → others

Most famous ones:

Number Permissions Looks like Typical use case
755 rwxr-xr-x Owner full, others run/read Scripts, binaries, most public folders
644 rw-r–r– Owner edit, everyone read Normal files, configs, html/php
700 rwx—— Only owner full Private folders (~/.ssh, keys)
600 rw——- Only owner read/write Private keys (.pem, .env, passwords)
775 rwxrwxr-x Owner+group full, others read/run Shared team folders
666 rw-rw-rw- Everyone read/write Rare – dangerous, only temp shared files

Examples:

Bash

3. Recursive (-R) – Change Folder + Everything Inside

Super common – don’t forget the capital -R!

Bash

Warning: Be very careful with -R on important system folders — one wrong chmod can break your computer!

4. Real-Life Examples from Hyderabad Developer Life

Fix “Permission denied” on script

Bash

Secure your .env file

Bash

Fix website not loading / writable issue

Bash

Make shared folder for friends

Bash

Quick Practice Right Now (5 Minutes!)

Bash

Summary Table – chmod Cheat Sheet

Goal Symbolic Example Numeric Example When to use
Make script runnable chmod +x file.sh chmod 755 Every script!
Normal file (read by all) chmod u=rw,go=r file.txt chmod 644 Docs, code, html
Private key / secret chmod u=rw,go= file.key chmod 600 .env, ssh keys
Private folder chmod u=rwx,go= folder/ chmod 700 ~/.ssh, secrets
Shared team folder chmod ug=rwx,o=rx folder/ chmod 775 Team projects
Recursive on whole directory chmod -R +x scripts/ chmod -R 755 Servers, backups

Got the magic wand now? chmod is how you tell Linux “who can do what with this file/folder” — use it carefully, check with ls -l after every change.

Any part confusing? Want next: “Teacher, explain umask (default permissions when creating files)” or “what happens with setuid/setgid/sticky bit” or “chmod in scripts & cron”?

Just say — teacher is ready in Hyderabad! Keep chmod-ing and ls -l-ing every day! 🐧🔧🔐 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *