Lab 07: Understanding Permissions

Objective

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.

Time: 30 minutes | Level: Foundations | Docker: docker run -it --rm ubuntu:22.04 bash


Step 1: Reading the Permission String

ls -la /tmp/

📸 Verified Output:

total 8
drwxrwxrwt 1 root root 4096 Mar  5 00:57 .
drwxr-xr-x 1 root root 4096 Mar  5 00:57 ..

The first column (drwxrwxrwt) is the permission string. Break it down:

d  rwx  rwx  rwt
│   │    │    └── Other (everyone else) permissions
│   │    └─────── Group permissions
│   └──────────── Owner permissions
└──────────────── File type: d=directory, -=file, l=symlink

Each rwx block: r=read, w=write, x=execute. - = permission not granted.


Step 2: Real-World Examples

📸 Verified Output:

File
Perm string
Meaning

/bin/ls

-rwxr-xr-x

Owner: rwx, Group: r-x, Other: r-x — everyone can run it

/etc/passwd

-rw-r--r--

Owner: rw, Group: r, Other: r — everyone can read

/etc/shadow

-rw-r-----

Owner: rw, Group: r, Other: none — hashed passwords!

💡 /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.


Step 7: Check Your Understanding

📸 Verified Output:


Step 8: Capstone — Security Permission Audit

📸 Verified Output:


Summary

Permission
Octal
File effect
Directory effect

r

4

Read content

List contents (ls)

w

2

Modify content

Create/delete files

x

1

Execute

Enter directory (cd)

s (SUID)

4000

Run as owner

(rarely used)

s (SGID)

2000

Run as group

New files inherit group

t (sticky)

1000

Only owner can delete own files

Last updated