Read and interpret Linux file permissions: the permission string, octal notation, owner/group/other, special bits (sticky, setuid, setgid). Understanding permissions is critical for both security hardening and daily administration.
💡 /etc/shadow stores hashed passwords. It's readable only by root and the shadow group. If it were world-readable, any user could attempt to crack the hashes offline.
Step 3: Octal (Numeric) Notation
📸 Verified Output:
Each digit = sum of: r=4, w=2, x=1
💡 Memorise these common permission values: 644 (config files), 755 (executables/dirs), 600 (private keys), 700 (private dirs), 777 (DO NOT USE in production).
Step 4: What Each Permission Means for Files vs Directories
📸 Verified Output:
Step 5: The Sticky Bit
📸 Verified Output:
The 1 prefix = sticky bit. Effect on directories: only the file owner can delete their own files, even if others have write access to the directory.
📸 Verified Output:
The t at the end = sticky bit. Without it, any user with write access to the directory could delete any other user's files.
Step 6: SetUID Bit
📸 Verified Output:
The s in owner execute position = SetUID. When any user runs /usr/bin/passwd, it temporarily runs as root — allowing it to write to /etc/shadow which only root can modify.
💡 SetUID binaries are a prime target in privilege escalation. find / -perm -4000 2>/dev/null finds all SUID binaries on a system. Any SUID binary with a vulnerability can be exploited for root access.
mkdir /tmp/permtest
touch /tmp/permtest/file.txt
echo "=== For FILES ==="
echo "r (read=4): cat, head, tail, grep the file"
echo "w (write=2): echo > file, vim, truncate"
echo "x (execute=1): ./script.sh, run a binary"
echo ""
echo "=== For DIRECTORIES ==="
echo "r (read=4): ls — list directory contents"
echo "w (write=2): touch, rm, mv — create/delete files inside"
echo "x (execute=1): cd — enter the directory, access files by name"
# Demonstrate x on dirs
chmod 644 /tmp/permtest # remove x from dir
cd /tmp/permtest 2>&1 || echo "Cannot cd: x bit missing"
chmod 755 /tmp/permtest # restore
cd /tmp/permtest && echo "Can cd now: x bit restored" && cd /tmp
=== For FILES ===
r (read=4): cat, head, tail, grep the file
w (write=2): echo > file, vim, truncate
x (execute=1): ./script.sh, run a binary
=== For DIRECTORIES ===
r (read=4): ls — list directory contents
w (write=2): touch, rm, mv — create/delete files inside
x (execute=1): cd — enter the directory, access files by name
bash: cd: /tmp/permtest: Permission denied
Cannot cd: x bit missing
Can cd now: x bit restored
stat -c '%a %n' /tmp
1777 /tmp
# Verify sticky bit in symbolic notation
ls -ld /tmp
drwxrwxrwt 1 root root 4096 Mar 5 00:57 /tmp
ls -la /usr/bin/passwd
-rwsr-xr-x 1 root root 59976 Feb 6 2024 /usr/bin/passwd
# Decode these permission strings:
for perm_example in "644" "755" "600" "700" "777" "1777"; do
python3 -c "
import stat, os
p = int('$perm_example', 8)
r = stat.filemode(p)
print(f' {\"$perm_example\":>5} = {r}')
"
done