Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 2 of 10

Users, Groups & File Permissions

Linux's permission model is the foundation of system security. Misconfigurations in file permissions are consistently among the most exploited vulnerabilities during penetration tests - they often allow attackers to read sensitive files, execute unauthorized code, or escalate privileges.

50 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Understanding the Permission Model

Understanding the Permission Model
# Permission format: [type][owner][group][others]
# Example: -rwxr-xr--
#
# Position 1:   File type: - (file) d (directory) l (symlink)
# Positions 2-4: Owner permissions (rwx = read, write, execute)
# Positions 5-7: Group permissions
# Positions 8-10: Others permissions

ls -la /etc/passwd
# -rw-r--r-- 1 root root 1872 Jan 15 2025 /etc/passwd
# Owner (root): rw- = read and write
# Group (root): r-- = read only
# Others:       r-- = read only (intentional - usernames are not secret)

ls -la /etc/shadow
# -rw-r----- 1 root shadow 1341 Jan 15 2025 /etc/shadow
# Owner (root): rw- = read and write
# Group (shadow): r-- = read only (only shadow group members)
# Others: --- = NO ACCESS (hashed passwords are secrets)

# Numeric (octal) notation:
# r=4, w=2, x=1
# rwx = 7, rw- = 6, r-x = 5, r-- = 4, --- = 0
chmod 644 file.txt    # Owner: rw-, Group: r--, Others: r-- (standard file)
chmod 600 private.key # Owner: rw-, Group: ---, Others: --- (SSH private key)
chmod 700 script.sh   # Owner: rwx, Group: ---, Others: --- (private script)
chmod 755 /usr/bin/tool # Owner: rwx, Group: r-x, Others: r-x (shared binary)

Dangerous SUID, SGID & Sticky Bit

Dangerous SUID, SGID & Sticky Bit
# SUID (Set User ID) - execute as file owner, not current user
# When a binary with SUID runs, it has the permissions of the owner
# /usr/bin/passwd has SUID set - runs as root so it can write to /etc/shadow

ls -la /usr/bin/passwd
# -rwsr-xr-x root root  # 's' in owner execute position = SUID

# SUID is a CRITICAL privilege escalation vector in pentesting
# Find all SUID binaries on a system:
find / -perm -u=s -type f 2>/dev/null
# Check each result against GTFOBins (gtfobins.github.io) for exploits

# Common exploitable SUID binaries:
# /usr/bin/find   → find /etc/passwd -exec /bin/sh -p ; (shell as root)
# /usr/bin/vim    → :shell (drops to root shell)
# /usr/bin/python3 → python3 -c 'import os; os.execl("/bin/sh","sh","-p")'

# SGID (Set Group ID) - execute with group permissions
# Sticky Bit on directories - only file owner can delete (used on /tmp)
ls -la /tmp
# drwxrwxrwt  # 't' = sticky bit - anyone can write, only owner can delete

Permission Auditing Best Practices

Permission Auditing Best Practices
# Find world-writable files (dangerous - anyone can modify)
find / -type f -perm -o+w 2>/dev/null | grep -v /proc | grep -v /sys

# Find world-writable directories (potential for file planting)
find / -type d -perm -o+w 2>/dev/null | grep -v /tmp | grep -v /var

# Find SUID and SGID files (privilege escalation risk)
find / -perm /6000 -type f 2>/dev/null

# Correct sensitive file permissions
chmod 600 ~/.ssh/id_rsa          # Private SSH key - owner read/write only
chmod 644 ~/.ssh/id_rsa.pub      # Public SSH key - readable by all
chmod 700 ~/.ssh/                # SSH directory - owner only
chmod 644 /etc/passwd            # User database - readable by all
chmod 640 /etc/shadow            # Password hashes - root + shadow group only
chmod 600 /etc/crontab           # Cron jobs - root only

Common Mistakes

  • Using chmod 777 on files or directories - grants full read/write/execute to everyone on the system; use the minimum required permissions
  • Leaving unnecessary SUID binaries - each SUID binary is a potential privilege escalation path; audit and remove SUID from binaries that don't need it
  • Not restricting ownership - files in /tmp or shared directories should have restricted permissions to prevent tampering by other users
  • Ignoring world-writable files in scripts - if a world-writable script is called by a root cron job, any user can inject malicious commands

Tip

Tip

Practice Users Groups File Permissions in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).

Practice Task

Note

Practice Task - (1) Write a working example of Users Groups File Permissions from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Users Groups File Permissions is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.

Key Takeaways

  • Linux's permission model is the foundation of system security.
  • Using chmod 777 on files or directories - grants full read/write/execute to everyone on the system; use the minimum required permissions
  • Leaving unnecessary SUID binaries - each SUID binary is a potential privilege escalation path; audit and remove SUID from binaries that don't need it
  • Not restricting ownership - files in /tmp or shared directories should have restricted permissions to prevent tampering by other users

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done