MODULE 04 — LINUX

File Permissions

rwx, chmod, chown — control who can read, write, and execute every file on the system. Misconfigurations here are one of the top privilege escalation vectors.

Why Permissions Matter

File permissions are the foundation of Linux security. They determine who can read, write, and execute every file on the system. A single misconfiguration — like making a private SSH key world-readable or a script writable by everyone — can lead to a complete system compromise.

In cybersecurity, permission misconfigurations are one of the top privilege escalation vectors. During a penetration test, one of the first things you check is: Are there any writable scripts that run as root? Are there SUID binaries that can be exploited? Are sensitive files readable by unauthorized users?

Linux uses a simple but powerful model: every file has an owner, belongs to a group, and has rules for everyone else. Each of these three categories can independently be granted or denied read, write, and execute permissions.

Key Terms

chmod: Change mode — the command that modifies file permissions using octal or symbolic notation.
chown: Change ownership — changes which user and group own a file.
SUID: Set User ID — a special permission bit that makes a program run with the file owner's privileges (often root).
umask: A default permission mask that determines what permissions new files are created with. Common value: 022 (files: 644, dirs: 755).
ACL: Access Control List — an extended permission system that allows fine-grained access for specific users beyond owner/group/others.
Sticky Bit: A special permission on directories that prevents users from deleting files they don't own (used on /tmp).

Understanding rwx Permissions

Every file and directory in Linux has three types of permission for three groups. Importantly, permissions mean different things for files vs. directories:

r (Read)
File: View/read the file's contents (e.g., cat)
Dir: List files inside (e.g., ls)
4
w (Write)
File: Modify/edit the file's contents
Dir: Create, delete, or rename files inside
2
x (Execute)
File: Run the file as a program/script
Dir: Enter the directory (cd into it)
1
Important: A directory with r but no x lets you list filenames but not access the files inside. A directory with x but no r lets you access files if you know their name, but you can't list them. Both are needed for normal use.

Permission Groups

When you run ls -la, the permission string shows 10 characters. The first is the file type, then three groups of three permissions each:

-rwxr-xr--
type owner group others

Octal (Numeric) Notation

The octal system represents permissions as numbers. Each permission has a value: r=4, w=2, x=1. You add them together for each group. Three digits = owner, group, others.

Octal Binary Permission Meaning
7 111 rwx Read + Write + Execute (4+2+1)
6 110 rw- Read + Write (4+2)
5 101 r-x Read + Execute (4+1)
4 100 r-- Read only (4)
2 010 -w- Write only (2)
1 001 --x Execute only (1)
0 000 --- No permissions
Common Permission Patterns:
755 (rwxr-xr-x) — Executable scripts, public directories
644 (rw-r--r--) — Regular files (default for new files)
600 (rw-------) — Private files (SSH keys, configs with passwords)
700 (rwx------) — Private directories, home dirs
777 (rwxrwxrwx) — ⚠️ DANGEROUS — everyone has full access!
000 (---------) — No one can access (except root)

Real-World: SSH Key Permissions

SSH is extremely strict about file permissions. If your private key (~/.ssh/id_rsa) is readable by anyone other than you, SSH will refuse to use it and display: WARNING: UNPROTECTED PRIVATE KEY FILE!

chmod 700 ~/.ssh — Directory: only owner can access
chmod 600 ~/.ssh/id_rsa — Private key: only owner can read/write
chmod 644 ~/.ssh/id_rsa.pub — Public key: owner can write, everyone can read
chmod 600 ~/.ssh/authorized_keys — Authorized keys: only owner

chmod — Two Syntax Styles

There are two ways to use chmod: octal (numeric) mode and symbolic mode. Both achieve the same result — use whichever feels more intuitive.

Octal Mode

chmod 644 file.txt — rw-r--r-- (standard file)
chmod 755 script.sh — rwxr-xr-x (executable script)
chmod 600 id_rsa — rw------- (private key)
chmod 777 danger.sh — rwxrwxrwx ⚠️ (avoid!)
chmod 000 locked.txt — --------- (no access)

Symbolic Mode

chmod u+x file — Add execute for owner
chmod g-w file — Remove write from group
chmod o= file — Remove all perms for others
chmod a+r file — Add read for all (a=ugo)
chmod u=rwx,go=rx file — Set exact perms (=755)

In symbolic mode: u=owner, g=group, o=others, a=all. +=add, -=remove, ==set exactly. Use -R for recursive: chmod -R 755 directory/

Special Permissions (SUID, SGID, Sticky)

Beyond the standard rwx permissions, Linux has three special permission bits that modify how files and directories behave. These are represented by a fourth digit in octal notation (e.g., 4755).

SUID (4xxx)

When a file has SUID set, it executes with the privileges of the file's owner, not the user who runs it. For example, /usr/bin/passwd is owned by root and has SUID — this lets regular users change their own password (which requires writing to /etc/shadow, a root-only file).

chmod 4755 program → -rwsr-xr-x

⚠️ #1 privilege escalation vector! If an SUID binary has a vulnerability (like a buffer overflow or command injection), an attacker can exploit it to execute commands as root.

find / -perm -4000 2>/dev/null

^ This command finds all SUID binaries — the first thing to check during privilege escalation.

SGID (2xxx)

On files: The program runs with the group privileges of the file's group, not the user's group. Used for programs that need to access group-owned resources.

On directories: New files created inside inherit the directory's group instead of the user's default group. This is essential for shared project folders where multiple developers need access.

chmod 2755 shared_dir/ → drwxr-sr-x

The s in the group execute position indicates SGID.

Sticky Bit (1xxx)

When set on a directory, only the file owner, directory owner, or root can delete/rename files inside — even if the directory is world-writable.

The classic example is /tmp: everyone can create files there, but you can only delete your own files. Without the sticky bit, any user could delete any other user's temp files.

chmod 1777 /tmp → drwxrwxrwt

The t at the end indicates the sticky bit.

SUID Exploitation — Privilege Escalation

SUID exploitation is one of the most common Linux privilege escalation techniques. If a root-owned SUID binary can be tricked into running arbitrary commands, you get root access.

Example: Exploiting a vulnerable SUID binary

Suppose /usr/local/bin/backup is SUID root and runs tar without a full path. An attacker can create a malicious tar in their PATH:

$ echo '/bin/bash' > /tmp/tar
$ chmod +x /tmp/tar
$ export PATH=/tmp:$PATH
$ /usr/local/bin/backup
# root shell!

Common SUID binaries to check (GTFOBins)

These standard Linux binaries, when SUID, can often be exploited for privilege escalation. Check GTFOBins for exploitation methods:

find vim python perl nmap bash less awk cp env

chown & chgrp — Changing Ownership

Permissions control what you can do; ownership controls who the permissions apply to. Only root can change file ownership (otherwise, any user could "give" their malicious files to root).

chown user:group file — Change both owner and group simultaneously
chown root file.txt — Change owner to root (keeps existing group)
chown :www-data file.txt — Change only the group (note the colon)
chgrp developers project/ — Change group using chgrp
chown -R www-data:www-data /var/www — Recursive: change entire web directory
Web Server Example: When deploying a website, you typically set ownership to the web server user: chown -R www-data:www-data /var/www/html and permissions to 755 (directories) and 644 (files). This lets the web server read everything but not modify files.

ACLs — Beyond Owner/Group/Others

Standard Linux permissions only allow three categories (owner, group, others). Access Control Lists (ACLs) let you set permissions for specific individual users or groups, providing much finer-grained control.

getfacl file.txt — View ACLs on a file
setfacl -m u:alice:rw file.txt — Give alice read/write access specifically
setfacl -m g:devops:rx project/ — Give devops group read/execute on directory
setfacl -x u:alice file.txt — Remove alice's ACL entry
setfacl -b file.txt — Remove all ACLs

When a file has ACLs, ls -la shows a + after the permission string: -rw-r--r--+. ACLs are essential in enterprise environments where simple owner/group/others isn't flexible enough.

Permission Simulator

Fix the file permissions using chmod. The visual grid updates in real-time!

Click bits to toggle — or use the terminal below

Type
Owner
Group
Others
-
r
w
-
r
-
-
r
-
-
Symbolic:
-rw-r--r--
Octal:
644

Challenges — Use chmod in the terminal

1Make script.sh executable by everyone: chmod 755 script.sh
2Secure id_rsa (owner read/write only): chmod 600 id_rsa
3Make config.cfg readable by all, writable by owner: chmod 644 config.cfg
4Remove all permissions from danger.sh: chmod 000 danger.sh
user@secplus:~/permissions$
Permission Lab — type 'ls -la' to see files, use chmod to change permissions.
user@secplus:~/permissions$

Knowledge Check

All certification names are referenced for educational purposes only. This project is not affiliated with any certification body.