EDGE CLUSTERS: yt-dl.unixcorn.org (Media Suite) tor.unixcorn.org (Privacy Archive) cloud.unixcorn.org (Homelab Hub) paste.unixcorn.org (Encrypted Paste) unixcorn.org (DevOps Tools)
LINUX DEVOPS UTILITY

Chmod Permissions Matrix & Decoder

Interactive bidirectional calculator for Linux file permissions. Converts between octal numbers and symbolic notation with special permission flags.

Common Presets:
Target Read (4) Write (2) Execute (1)
Owner (u)
Group (g)
Others (o)
Special Permission Bits:
bash • chmod execution
chmod 755 /var/www/html

📘 Comprehensive Linux File Permissions & Octal Architecture Guide

In Unix-like operating systems (Linux, macOS, FreeBSD, OpenBSD), every file and directory is governed by a strict Discretionary Access Control (DAC) permission model. Understanding this permission architecture is essential for systems administrators, DevOps engineers, and security auditors to maintain principle-of-least-privilege boundaries and prevent privilege escalation vulnerabilities.

1. The rwx Triad and Binary Octal Mathematics

Linux permissions evaluate access across three distinct user categories: Owner (User), Group, and Others (World). For each category, access rights are represented by three individual bits: Read (r), Write (w), and Execute (x). In octal notation, each permission corresponds to a power of two in binary:

Permission Symbolic Binary Bit Octal Value File Access Meaning Directory Access Meaning
Read r 100 4 Read file contents (e.g. cat, less) List directory contents (e.g. ls)
Write w 010 2 Modify, edit, or overwrite file contents Create, delete, or rename files in directory
Execute x 001 1 Execute binary executable or shell script Traverse / change into directory (e.g. cd)
No Permission - 000 0 Access completely denied for this tier Access completely denied for this tier

2. Production Permission Reference Matrix

Below are the most frequently deployed permission codes across Linux servers, continuous deployment pipelines, and cloud containers:

Octal Code Symbolic Representation Security Classification Production Use Cases
755 rwxr-xr-x Standard Public Executable binaries in /usr/bin, public web directories, traversable parent paths.
644 rw-r--r-- Standard Read Standard web assets (HTML, CSS, JS), static images, configuration templates, log files.
700 rwx------ Private Executable User ~/.ssh/ directory, root maintenance scripts, user-private daemon sockets.
600 rw------- Confidential Private keys (id_rsa, id_ed25519), .env database credentials, SSL private keys.
400 r-------- Read-Only Secrets Cloud instance IAM keys, AWS pem keys, read-only hardware tokens, archival backups.
777 rwxrwxrwx Severe Danger Never use in production. Grants arbitrary write/execute access to all local/web processes.

3. Special Modes: SUID, SGID, and the Sticky Bit

When advanced access control is required, an optional leading fourth digit is used:

  • SUID (Set User ID - 4000): When an executable binary with SUID (e.g. chmod 4755 /usr/bin/passwd) is invoked by an unprivileged user, it runs with the effective privileges of the file's owner (typically root).
  • SGID (Set Group ID - 2000): When applied to a collaborative shared directory (e.g. chmod 2775 /var/www/team_share), any file created inside automatically inherits the group of the parent directory rather than the primary group of the creating user.
  • Sticky Bit (1000): When applied to shared writable directories (e.g. chmod 1777 /tmp), only the file owner, the directory owner, or the root superuser can delete or rename the files inside, preventing malicious cross-user deletion.

4. Battle-Tested Sysadmin Command Recipes

# Recursively secure all web directories to 755 without affecting files:
find /var/www/html -type d -exec chmod 755 {} +

# Recursively secure all web files to 644 without removing directory execution:
find /var/www/html -type f -exec chmod 644 {} +

# Lock down an OpenSSH private key so SSH client doesn't reject it:
chmod 600 ~/.ssh/id_ed25519 && chmod 700 ~/.ssh

# Protect production environment credentials from web server snooping:
chmod 600 /var/www/app/.env && chown deploy_user:www-data /var/www/app/.env

❓ Linux File Permissions FAQ

Common questions regarding octal calculation, web server security, and Linux access control.

What is the mathematical difference between octal and symbolic chmod notation?

In Linux file systems, permissions are represented in octal (base-8) by adding binary bit weights: Read (r = 4), Write (w = 2), and Execute (x = 1). For example, Read + Write + Execute equals 4 + 2 + 1 = 7, while Read + Execute equals 4 + 1 = 5. Symbolic notation modifies permissions relative to identities (u for user/owner, g for group, o for others, and a for all). Using chmod 755 script.sh sets owner to 7 (rwx), group to 5 (r-x), and others to 5 (r-x), which is identical to chmod u=rwx,go=rx script.sh.

Why is running 'chmod -R 777' considered a catastrophic security vulnerability?

Executing chmod -R 777 grants unrestricted Read, Write, and Execute privileges to every local user, background service, and potentially compromised web daemon (such as www-data or nobody). If a web application suffers from an arbitrary file upload or local file inclusion vulnerability, an attacker can upload malicious scripts and execute them directly with the web server's permissions, leading to full remote code execution (RCE) and local privilege escalation.

What are the standard secure permissions for web servers running Nginx or Apache?

The industry gold standard for production web roots (e.g. /var/www/html) is 755 (drwxr-xr-x) for directories and 644 (-rw-r--r--) for files, with ownership assigned to the deploy user and group set to the web daemon (www-data:www-data). Directories require execute permissions so the web daemon can traverse into them. Sensitive configuration files containing database passwords (e.g., wp-config.php or .env) should be locked down to 600 (-rw-------) or 640 (-rw-r-----).

What are SUID, SGID, and the Sticky Bit special permissions?

Special permissions represent an optional 4th leading octal digit. SUID (Set Owner User ID, octal 4000) executes the binary with the file owner's privileges (e.g., /usr/bin/passwd). SGID (Set Group ID, octal 2000) enforces newly created files in a directory to inherit the parent directory's group. The Sticky Bit (octal 1000), famously applied to /tmp (chmod 1777), prevents non-root users from deleting or renaming files owned by other users within that shared directory.

How do I recursively fix directory permissions without breaking executable files in Linux?

Never use chmod -R with a static permission code on mixed directories. Instead, use the find command: to recursively set all directories to 755, run find /path/to/dir -type d -exec chmod 755 {{}} +. To recursively set all regular files to 644, run find /path/to/dir -type f -exec chmod 644 {{}} +. This ensures scripts and binaries do not lose execute rights while directories remain traversable.