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
SymbolMeaningNotes
rReadFiles: view contents. Directories: list contents with ls
wWriteFiles: modify. Directories: create/delete files inside
xExecuteFiles: run as a program. Directories: enter with cd
-No permissionThat permission is not granted

Changing Permissions (chmod)

bash
# Symbolic mode — easier to understand
chmod u+x script.sh # Add execute for the owner (user)
chmod g-w file.txt # Remove write from the group
chmod o-rx file.txt # Remove read+execute from others
chmod 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 group
chmod 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 alice
sudo chown alice:staff file.txt # Change owner AND group
sudo chgrp developers project/ # Change group only
sudo 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?

0 XP🔥 0 days