Search tools

Developer guides

chmod 777 vs 755: Why 777 Is Dangerous and What to Use Instead

Running chmod 777 fixes permission errors fast, but it gives every user and process write access. Here is why web servers reject it and what to use instead.

3D dark glassmorphic consoles comparing an open red permission portal with a secure cyan biometric vault seal

When your web app throws a Permission denied error, typing chmod -R 777 feels like magic. The error disappears instantly. Your upload works, your script runs, and you move on.

It is also one of the most dangerous commands you can run on a Linux server.

The quick rule is simple: use 755 for directories and 644 for regular files. Never use 777 on a server that touches the internet.

You can inspect the exact permission bits for both modes in our interactive chmod calculator.

Here is why 777 is dangerous, why web servers actively reject it, and how to fix permissions safely.

What 777 and 755 actually mean

Every file and directory in Linux has three permission tiers: Owner, Group, and Others (everyone else). Each tier gets a digit representing Read (4), Write (2), and Execute (1).

In chmod 777, all three digits are 7 (4 + 2 + 1): - Owner: Read, Write, Execute (rwx) - Group: Read, Write, Execute (rwx) - Others: Read, Write, Execute (rwx)

That third 7 means any account on the system can modify, overwrite, or delete the file. If an attacker finds a vulnerability in a neighboring service, or if an unprivileged background process is compromised, they can write executable code directly into your files.

In chmod 755, the public write bit is removed: - Owner: Read, Write, Execute (rwx, 7) - Group: Read, Execute (r-x, 5) - Others: Read, Execute (r-x, 5)

With 755, only the file owner can modify or delete the contents. Everyone else can inspect and run them, but they cannot tamper with them.

# Dangerous: anyone can overwrite
-rwxrwxrwx 1 www-data www-data 1024 index.php

# Safe default: only owner can modify
-rwxr-xr-x 1 www-data www-data 1024 index.php

Why modern web servers reject 777

Web servers like Nginx, Apache, and OpenSSH often refuse to run when permissions are set to 777.

If you configure PHP-FPM or suEXEC, the process manager checks the permissions of your scripts before executing them. If a script or its parent directory is world-writable, the server aborts with an HTTP 500 Internal Server Error.

The server does this to protect you. On a shared host, world-writable scripts let any tenant inject malicious payloads into your application. If you have ever seen an SSH key fail to connect, our guide to fixing SSH key permissions explains how OpenSSH enforces the exact same safeguard.

The safe standard for web projects

Instead of setting 777 across your entire project, split your files and directories into their proper standards:

  1. Directories need 755: Linux needs execute (+x) permission on a folder just to enter it (cd) and read its directory table.
  2. Files need 644: Regular code files, images, and HTML never need execute permission. They only need read and write for the owner, and read for everyone else.

Run these two commands from your project root:

# Set directories to 755
find . -type d -exec chmod 755 {} +

# Set files to 644
find . -type f -exec chmod 644 {} +

What about writable upload folders?

If your app needs to save user avatars or file uploads, do not make the folder 777. Change the ownership to the web server user instead:

# On Ubuntu/Debian:
sudo chown -R www-data:www-data storage/uploads/
chmod 775 storage/uploads/

With 775, you and the web server group share write access, while the outside world (Others) remains read-only.

If you ever need to verify numeric permission values quickly or test special bits, check our chmod calculator to generate exact octal and symbolic commands instantly.

Read next