Linux Fundamentals · 3.4
🔏 Linux File Permissions
rwxrwxrwx — reading the permission bits⏱ ~2 min
Every file and directory in Linux has three permission sets: one for the Owner, one for the Group, and one for Others. Each set has three bits: read (r), write (w), and execute (x).
Reading Permission Strings
bash
ls -l pythagoras.sh# Output: -rwxr-x--- 1 cyberpatriot users 2048 Jun 18 08:00 pythagoras.sh# ^ type# ^^^ owner permissions (rwx = read, write, execute)# ^^^ group permissions (r-x = read, execute; no write)# ^^^ other permissions (--- = no access)# Owner: cyberpatriot Group: users| Symbol | Meaning | Notes |
|---|---|---|
| r | Read | Files: view contents. Directories: list contents with ls |
| w | Write | Files: modify. Directories: create/delete files inside |
| x | Execute | Files: run as a program. Directories: enter with cd |
| - | No permission | That permission is not granted |
Changing Permissions (chmod)
bash
# Symbolic mode — easier to understandchmod u+x script.sh # Add execute for the owner (user)chmod g-w file.txt # Remove write from the groupchmod o-rx file.txt # Remove read+execute from otherschmod a+r public.txt # Add read for All (owner+group+others) # Numeric (octal) mode — faster once you know it# r=4, w=2, x=1 — add up the digits for each groupchmod 755 script.sh # owner: rwx(7), group: r-x(5), others: r-x(5)chmod 644 config.txt # owner: rw-(6), group: r--(4), others: r--(4)chmod 600 secret.key # owner: rw-(6), group: ---(0), others: ---(0)chmod 700 private/ # owner: rwx(7), group: ---(0), others: ---(0)Changing Ownership (chown, chgrp)
bash
sudo chown alice file.txt # Change owner to alicesudo chown alice:staff file.txt # Change owner AND groupsudo chgrp developers project/ # Change group onlysudo chown -R alice mydir/ # Recursive: change owner of all files inside🔒 SecurityWorld-writable files (others have write permission) are serious vulnerabilities. Find them with: find / -perm -o+w -not -path '/proc/*' -not -path '/sys/*' 2>/dev/null. Any sensitive file with world-write is a security finding in competition.
🧠Quick Checkfirst try = +5 XP
What does chmod 777 file.txt do — and should you?
🎮 Practice what you learned
⭐ 0 XP🔥 0 days