Chmod 755 vs 644 vs 777 Explained: Linux File Permissions Security Guide
Understand octal Linux permissions: why directories use chmod 755 (drwxr-xr-x), static config/web files use 644 (-rw-r--r--), SSH private keys require 600 (-rw-------), and why chmod 777 creates severe security exposure.
In-Depth Analysis — Chmod 755 vs 644 vs 777 Guide
Octal Bitmask Math (4 + 2 + 1) & File vs Directory Prefixes: Each octal digit sums Read (4), Write (2), and Execute/Traverse (1) across Owner, Group, and Others. In ls -l output, the first character indicates file type—'-' for regular files (-rwxr-xr-x) and 'd' for directories (drwxr-xr-x)—followed by the nine permission bits.
Why Web Directories Need 755 While Files Inside Need 644: Nginx, Apache, and Caddy worker processes need the directory execute/traverse bit (+x) to enter /var/www/html (chmod 755 -> drwxr-xr-x), while static assets inside (index.html, app.css) only need read access (chmod 644 -> -rw-r--r--). Apply both safely with find /var/www/html -type d -exec chmod 755 {} + and find /var/www/html -type f -exec chmod 644 {} +.
Why Chmod 777 Is Dangerous & Why SSH Rejects 644 Keys (Reviewed 2026-10-25): Setting chmod 777 (drwxrwxrwx / -rwxrwxrwx) lets any compromised process or local user modify scripts or upload web shells. Conversely, OpenSSH explicitly aborts with 'UNPROTECTED PRIVATE KEY FILE!' if ~/.ssh/id_ed25519 is readable by group/others—always lock private keys and .env files to chmod 600 (-rw-------) and ~/.ssh to chmod 700.
Standard Linux & Web Server Chmod Octal Modes Reference
POSIX permission bitmasks across Owner, Group, and Others (Read = 4, Write = 2, Execute = 1):
| Octal | File Symbolic | Directory Symbolic | Typical Production Use Case |
|---|---|---|---|
| 0600 (600) | -rw------- | drw------- | SSH private keys (~/.ssh/id_ed25519), .env secrets, TLS private keys |
| 0644 (644) | -rw-r--r-- | — (No traverse) | Static web assets (HTML, CSS, JS, images), public config files |
| 0700 (700) | -rwx------ | drwx------ | Private ~/.ssh directory, root-only cron/maintenance scripts |
| 0755 (755) | -rwxr-xr-x | drwxr-xr-x | Web server directories (/var/www), CLI binaries, CGI/shell scripts |
| 0775 (775) | -rwxrwxr-x | drwxrwxr-x | Shared deploy group directories (e.g. www-data + deploy user) |
| 0777 (777) | -rwxrwxrwx | drwxrwxrwx | World-writable (Avoid in production—security risk) |
Scenario Comparison & Benchmark Table (Chmod Calculator)
Compare how scaling the primary input changes results (click any row to load into calculator):
| Owner Octal (0-7: 4=Read, 2=Write, 1=Exec) | Chmod Command & Symbolic Mode | Owner / Group / Others | 4-Digit Octal Mode |
|---|---|---|---|
| 0 | chmod 055 path (----r-xr-x / d---r-xr-x) | --- / r-x / r-x | 0055 |
| 1 | chmod 155 path (---xr-xr-x / d--xr-xr-x) | --x / r-x / r-x | 0155 |
| 3 | chmod 355 path (--wxr-xr-x / d-wxr-xr-x) | -wx / r-x / r-x | 0355 |
| 4 | chmod 455 path (-r--r-xr-x / dr--r-xr-x) | r-- / r-x / r-x | 0455 |
| 6 | chmod 655 path (-rw-r-xr-x / drw-r-xr-x) | rw- / r-x / r-x | 0655 |
| 7 (Baseline) | chmod 755 path (-rwxr-xr-x / drwxr-xr-x) | rwx / r-x / r-x | 0755 |
Mathematical Formula & Step-by-Step Guide
Primary mathematical equation used by this model:
- Set Owner, Group, and Public/Others octal digits (0–7: Read = 4, Write = 2, Execute = 1), toggle the interactive 9-bit rwx checkbox matrix, or click a preset (755, 644, 600, 775).
- Copy the generated chmod command and inspect both regular-file (-rwxr-xr-x) and directory (drwxr-xr-x) symbolic representations.
- Verify least-privilege security: never use 777 on web roots or config files, and use 600 (0600) for SSH private keys and .env credentials.
All developer utilities execute locally in your browser with zero server-side logging of input payloads.