chmod 777: what it means
chmod 777 gives read, write and execute to the owner, the group and everyone else. It is the quick fix people paste when something says "permission denied", and it works because it removes every barrier at once. That is also the problem: any account on the machine, and any compromised service, can now change or replace that file.
The calculator shows this mode as rwxrwxrwx, and ls -l prints a regular file as -rwxrwxrwx and a directory as drwxrwxrwx. Open the page on that mode and toggle a box to see the number change.
Digit by digit
| Who | Digit | Bits | Can |
|---|---|---|---|
| Owner (u) | 7 | rwx | read, write, execute |
| Group (g) | 7 | rwx | read, write, execute |
| Others (o) | 7 | rwx | read, write, execute |
Each digit adds read = 4, write = 2 and execute = 1. For this mode the command is chmod 777 path, and the umask that produces it on a directory is 000.
Where it is used
- Almost never. A temporary 777 on a throwaway folder in a local test machine is the legitimate case.
- The shared world-writable directory /tmp is 1777, not 777: the sticky bit stops users from deleting each other's files.
- Docker bind mounts and shared folders often tempt people to use 777; the real fix is matching the user or group id.
Wide-open and special modes, side by side
| Mode | Symbolic | What it is for |
|---|---|---|
| 666 | rw-rw-rw- | Everyone reads and writes a file; it still cannot be executed. |
| 777 | rwxrwxrwx | Everything for everyone: avoid it on real servers. |
| 1777 | rwxrwxrwt | Everyone writes in the directory, only the owner of a file deletes it (/tmp). |
| 2775 | rwxrwsr-x | setgid directory: new files inherit the group, a good shared folder. |
| 4755 | rwsr-xr-x | setuid program: runs as its owner (as passwd does); dangerous in the wrong hands. |
The umask that sets the starting mode
New files start from 666 and new directories from 777; the umask removes bits. Computed with the calculator:
| umask | New files | New directories |
|---|---|---|
| 022 | 644 | 755 |
| 002 | 664 | 775 |
| 027 | 640 | 750 |
| 077 | 600 | 700 |
Commands
Find what is world-writable, and undo it
find /var/www -perm -0002 -not -type l -ls
find /var/www -type d -perm 777 -exec chmod 755 {} +
find /var/www -type f -perm 777 -exec chmod 644 {} +Instead of 777: give the group access
sudo chgrp -R www-data /var/www/uploads
sudo chmod -R 2775 /var/www/uploads
sudo usermod -aG www-data deployCommon mistakes
- Applying chmod -R 777 to the project folder to get past one error: it also makes every file executable and writable for everyone, and tools such as ssh and git hooks start to refuse files.
- Using 777 to fix "permission denied" without asking who the process runs as: the cause is usually the owner, so chown or chgrp fixes it with far less exposure.
- Leaving 777 on upload folders of a PHP site: an attacker who uploads a script there can run it. Uploads should be writable by the web user only and, ideally, never executed.
Frequently asked questions
Is chmod 777 dangerous?
On a shared or internet-facing machine, yes: it lets every user and every compromised service rewrite the file. On a private single-user test box the risk is small, but it is a bad habit to carry to production.
What should I use instead of 777?
Find which user needs access and give it exactly that: chown to that user, or put it in a group with 775 (2775 for a shared folder). Files are 644 and folders 755 by default.
What does the leading digit in 1777 or 4755 mean?
It holds the special bits: 4 is setuid, 2 is setgid, 1 is sticky. The calculator shows them as s, s and t in the symbolic form (rwxrwxrwt for 1777).