On a Linux operating system, security hinges on file permissions. Every program, configuration file, socket, and storage drive is represented as a file or directory with specific access boundaries. When administrators configure these boundaries correctly, low-privilege service accounts and users stay isolated within their operational roles.

When permissions drift or are configured too loosely, an attacker who gains entry through a compromised web application or leaked credential can often jump straight to administrative control. This process is known as privilege escalation (vertical escalation, where a standard user gains root rights). This guide breaks down Linux permission mechanics, how misconfigurations enable privilege escalation, and how to audit and harden your environment.

How Linux File Permissions Work

Linux tracks ownership and access using three tiers: the file owner (user), the assigned group, and everyone else (other). You can inspect these settings using the standard listing command:

ls -l /path/to/file

The output displays a 10-character string such as -rwxr-xr--. The first character identifies the file type (a dash - for a regular file, d for a directory, or l for a symlink). The remaining nine characters represent three triplets:

  • Read (r / 4): Allows reading the file contents or viewing directory contents.
  • Write (w / 2): Allows modifying file contents or adding/removing files within a directory.
  • Execute (x / 1): Allows executing the file as a program or entering (traversing) a directory.

For example, a file with permissions 750 translates to rwxr-x---. The owner has read, write, and execute rights (4+2+1=7); the group has read and execute rights (4+0+1=5); and other users have zero access (0).

Special Permissions: SUID, SGID, and Sticky Bits

Standard permissions determine access based on the person executing the action. However, standard users sometimes need temporary elevated privileges to perform routine tasks, such as changing their password via /usr/bin/passwd. Linux solves this with special permissions:

  • SUID (Set Owner User ID up on execution): Represented by an s in the owner execute position (e.g., -rwsr-xr-x, octal 4000). The program executes with the permissions of the file owner (often root), regardless of who launched it.
  • SGID (Set Group ID up on execution): Represented by an s in the group execute position (e.g., -rwxr-sr-x, octal 2000). When run, the program inherits the privileges of the file's group. In a directory, new files inherit the group of the parent directory.
  • Sticky Bit: Represented by a t in the other execute position (octal 1000). In shared directories like /tmp, it prevents users from deleting or renaming files owned by others.

Because SUID root binaries execute with full administrative authority, any security flaw or unintended administrative capability within those binaries can allow an attacker to spawn a shell with root rights.

Common Privilege Escalation Vectors

Attackers who gain an initial shell systematically review the local file system for misconfigurations. Here are the most frequent permission-related paths they take.

1. Dangerous SUID Executables

System tools that allow file inspection, editing, or arbitrary command execution should never have an SUID bit set. If an administrator assigns SUID to an editor like vim or a pager like less, any unprivileged user can launch that tool and drop directly into an interactive root shell or overwrite protected configuration files.

2. World-Writable Critical Files

System configuration files must belong strictly to root and should never be writable by the "other" tier. If an administrator accidentally assigns permissions like 777 (read, write, execute for all) to system files, security boundaries collapse:

  • /etc/passwd: If writable, an attacker can append a new line containing an account with user ID 0 and a known password hash.
  • /etc/sudoers: If writable, an attacker can append a directive granting their current account unrestricted, passwordless sudo access.
  • /etc/shadow: If readable by all, an attacker can extract password hashes for offline cracking.

3. Insecure Scheduled Tasks (Cron Jobs)

Administrative cron jobs often run with root rights on a fixed schedule. If the script being executed or the directory containing it is writable by lower-privileged users, an attacker can simply modify the script to execute their own commands the next time the job triggers.

4. Wildcard Expansion and Relative Paths

When scripts executed by root invoke programs using relative paths (e.g., running backup.sh instead of /usr/local/bin/backup.sh), Linux relies on the environment's PATH variable. If an unprivileged user can write to any directory earlier in the search path, they can place a malicious executable that root runs by mistake.

Auditing Your System Step-by-Step

You can identify permission vulnerabilities on your systems using standard GNU/Linux utilities without installing third-party tools.

Step 1: Discover All SUID and SGID Files

Run the following command to find all files with the SUID bit set, discarding error messages from virtual or inaccessible directories:

find / -perm -4000 -type f -exec ls -ld {} + 2>/dev/null

Review the resulting list. Legitimate binaries usually include tools like passwd, sudo, and su. Look for non-standard utilities, custom internal scripts, programming language binaries (like Python, Perl, or Bash), or administrative tools (like curl, nmap, or find). If an unusual binary has an SUID flag, remove it using chmod:

sudo chmod u-s /path/to/binary

Step 2: Check for World-Writable Files and Directories

Scan for files that any local user can modify across the root filesystem:

find / -xdev -type f -perm -0002 -exec ls -l {} + 2>/dev/null

The -xdev flag ensures the search stays on the current filesystem, avoiding virtual mounts like /proc and /sys. Aside from system temp spaces, very few files should be world-writable. Pay close attention to any script located in /opt, /usr/local, or /etc.

Step 3: Verify Ownership of Scheduled Tasks

Inspect permissions for system-wide crontabs and directories:

ls -la /etc/cron* /var/spool/cron/crontabs

Ensure that all scripts in /etc/cron.daily, /etc/cron.hourly, and related folders are owned by root:root and have write permissions restricted strictly to the owner (e.g., 755 or 700).

Hardening Best Practices

Preventing privilege escalation requires proactive configuration management rather than occasional manual cleanups.

  • Enforce a Strict Umask: The default user mask (umask) defines permissions on newly created files. Setting the system-wide umask to 027 or 077 ensures new files are not readable or writable by arbitrary users.
  • Mount Partitions with Protective Flags: In /etc/fstab, mount shared or temporary storage partitions like /tmp, /var/tmp, and /dev/shm with the nosuid and noexec mount options. This prevents users from executing binaries or abusing SUID binaries dropped in temporary folders.
  • Follow the Principle of Least Privilege: Avoid creating monolithic admin groups. Give users granular sudo permissions that point only to specific needed commands, and avoid granting wildcard execution permissions in the sudoers file.
  • Use Security Modules: Keep SELinux or AppArmor enabled in enforcing mode. These Mandatory Access Control (MAC) frameworks restrict what programs can do, even if an attacker manages to exploit a root-owned SUID program.

Defensive Checklist

  • Audited all SUID/SGID binaries and removed special bits from non-essential utilities.
  • Confirmed that /etc/passwd and /etc/sudoers are strictly owned by root and writable only by root.
  • Ensured /etc/shadow has read access restricted entirely to privileged accounts (mode 0640 or 0600).
  • Verified that cron jobs and scheduled service scripts cannot be edited by non-root users.
  • Configured nosuid on /tmp and shared storage mounts in /etc/fstab.
  • Set a secure default umask (such as 027) in global shell profiles.