chmod 777 sets rwxrwxrwx: the owner, the group and everyone else can read, change, delete and run the file. The calculator marks it with a warning:
Octal 777
Symbolic rwxrwxrwx (ls -l: -rwxrwxrwx)
Command chmod 777 file
owner 7 read write execute
group 7 read write execute
others 7 read write execute
Others can write: anyone on the system can modify this file.
You can see that warning in the chmod calculator when you open the example.
Why it is a bad habit
- Anyone can change the content. On a shared host, another account, or a compromised service running as another user, can modify your files.
- Executable by everyone. A data file marked 777 can be run, which helps a malicious upload.
- It hides the real problem. A “Permission denied” almost always means the wrong owner or group, and 777 makes the error disappear without fixing that.
- Some programs refuse to run. SSH rejects keys and config files with open permissions, and hosting setups that use suEXEC or suPHP refuse scripts and folders that anyone can write to, and answer with a 500.
- It spreads.
chmod -R 777on a folder changes everything inside, and the habit ends up in deployment scripts and Docker images.
What to do instead
Work out who needs access and give only that.
| Situation | Better than 777 |
|---|---|
| The web server must read the site | owner = you, files 644, folders 755 |
| The web server must write an upload or cache folder | chown www-data:www-data uploads and mode 755 or 750 |
| A team edits a shared folder | a shared group, mode 775, and chmod g+s so new files keep the group |
| A script must be run by everyone | 755, not 777 |
| A secret | 600 or 700 |
| A docker volume has wrong ownership | set the container user’s UID/GID to match the host folder, or chown it |
The legitimate 1777
The /tmp directory is world-writable, yet safe, because of the sticky bit: its mode is 1777 (shown as drwxrwxrwt). Everyone may create files there, but only a file’s owner (or the directory’s owner) may delete or rename it. If you really need a shared dropbox folder, give it the sticky bit instead of a plain 777: chmod 1777 /srv/dropbox.
If a 777 is already there
Find where it came from before you reset it: a deployment script, an installer, a tutorial. Then restore the pair of 755 for folders and 644 for files as shown on the 755 page, and re-add the execute bit only to scripts that need it. A web server that answers 403 Forbidden after that tells you which path still lacks access.
Frequently asked questions
Is chmod 777 ever acceptable?
Rarely: a throw-away directory on a machine only you use, or a test container. On a shared or public server it is a vulnerability. The nearest legitimate case is a sticky directory like /tmp, which is 1777: everyone may write, but only the owner can delete their own files.
Why does everyone suggest 777 when I get 'Permission denied'?
Because it works, and without understanding the problem. The real fix is to give the process that needs access the right owner or group, and the least permission it needs.
What is wrong with 777 for an upload folder?
Anyone who can run code on the machine can add or replace files there. If the folder is also inside the web root, an attacker who uploads a script can run it. Use the web server's user as owner with 755 or 750.
How do I undo a chmod -R 777?
Set folders and files separately: find . -type d -exec chmod 755 {} + and find . -type f -exec chmod 644 {} +. Then check scripts that need the execute bit again.
More in this reference
- chmod 400: read-only private files, such as .pem keys
- chmod 600: private files for SSH keys, .env and other secrets
- chmod 644: what rw-r--r-- means and why it is the default for files
- chmod 664: files that a group can edit (rw-rw-r--)
- chmod 700: private folders and scripts that only the owner can use
- chmod 755: what rwxr-xr-x means and when to use it
- chmod 775: shared folders and scripts for a group (rwxrwxr-x)