Python Changing Permissions with chmod: Symbolic & Octal Modes
The `chmod` (change mode) command modifies file and directory access permissions. You can specify permissions using numeric Octal notation (e.g. `chmod 755 file`) or Symbolic notation (e.g. `chmod u+x,g-w file`).
"Octal notation is like a 3-digit combination padlock: each digit represents the exact mathematical sum of permissions (Read=4, Write=2, Execute=1) for User, Group, and Other."
Deep Dive: How It Works
Octal Math: `r = 4`, `w = 2`, `x = 1`. Combinations: `7` (4+2+1 = rwx), `6` (4+2 = rw-), `5` (4+1 = r-x), `4` (4 = r--), `0` (---).
Standard Modes: `644` (rw-r--r--: standard web files/configs), `600` (rw-------: private keys/secrets), `755` (rwxr-xr-x: scripts and directories), `700` (rwx------: private scripts/.ssh).
Symbolic Notation: `u` (user), `g` (group), `o` (other), `a` (all); `+` (add), `-` (remove), `=` (set exact). Example: `chmod u+x,o-rwx script.sh`.
Syntax Blueprint
chmod 755 script.sh # rwxr-xr-x chmod 600 id_ed25519 # rw------- chmod +x deploy.sh # Add execute for user/group/other chmod -R 755 /var/www # Recursive permission change
Use octal chmod for absolute permissions and symbolic chmod (e.g. +x) for relative tweaks.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Setting `chmod 777` on sensitive production files or web roots.Why it happens: Developers use 777 to quickly fix permission errors.
How to fix: 777 allows any process or attacker on the system to overwrite your code. Use 755 for executables and 644 for files.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Make a Script Executable with chmod +x
Create `/tmp/exec_test.sh` with `echo "Hello"`.
Add execute permissions with `chmod +x /tmp/exec_test.sh`.
Verify with `ls -l /tmp/exec_test.sh` and clean up.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.