chmod 777 (rwxrwxrwx)
Every account on the system can read, change, run, delete and replace. It makes permission errors go away by switching permissions off, and there is almost always a narrower fix.
This tool runs in your browser. We never send what you type or paste to a server.
What chmod 777 sets
| Who | Digit | Read | Write | Execute | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | yes | yes | yes | rwx |
| Group (g) | 7 | yes | yes | yes | rwx |
| Others (o) | 7 | yes | yes | yes | rwx |
chmod 777 file # numeric
chmod a=rwx file # the same, in symbolic form
ls -l shows this mode as -rwxrwxrwx on a file and drwxrwxrwx on a directory. On a file, execute means it can be run as a program. On a directory, read lists the names inside, write creates, renames and deletes entries, and execute (search) is what lets you enter it and reach the files inside.
What 777 actually allows
On a directory, any local account can add files and can delete or replace the ones already there, whatever those files' own modes say. On a file, anyone can rewrite a program that someone else will run later.
"Any account" includes the ones services run under, and that is where the damage comes from:
- Web applications. A bug that lets an attacker write a file is far worse when the web server's user can write everywhere. With code at 755 and 644 under a different owner, the same bug cannot modify the application.
- Shared machines. Another user can alter a script you run or a file your shell reads at login, and their commands then run as you.
- Software that refuses to cooperate. sshd ignores
authorized_keyswhen the file,~/.sshor your home directory is writable by others, and ssh ignores a private key that others can read.
On a laptop only you use, or in a throwaway container, the practical risk is smaller.
What to do instead
"Permission denied" means the program runs as a user the current mode does not cover. Give that one user access:
ls -ld /srv/app/cache # who owns it now
ps -o user= -p 1234 # the user that process 1234 runs as
chown -R appuser /srv/app/cache # as root: make that user the owner
If more than one account needs to write, use a shared group with 775 on directories and 664 on files. Apply it to the directory that has to be written to, not to the whole tree.
If 777 did not cure the error, the mode was never the cause. Look for a parent directory without execute permission for that user, a file system mounted read-only or noexec, or a security module such as SELinux or AppArmor.
Recovering from chmod -R 777
There is no undo: chmod keeps no record of the old modes. What you can do depends on where it was run.
Your own project or web root. Reset to the defaults, then restore the exceptions by hand:
find project -type d -exec chmod 755 {} +
find project -type f -exec chmod 644 {} +
chmod 755 project/deploy.sh # scripts that are run directly
chmod 600 project/.env # anything secret
In a Git working tree the executable bit is the only permission Git tracks, so git diff lists the files whose bit no longer matches the last commit.
Your home directory. As above, plus chmod 700 ~/.ssh, chmod 600 on the private keys, and chmod go-w ~.
System directories (/, /usr, /etc, /var). This is serious. Setting 777 on a file also strips its setuid and setgid bits, so sudo stops with "must be owned by uid 0 and have the setuid bit set", and sshd will not start while its host keys are readable by others. Restore from a backup or snapshot if you have one. On RPM-based systems rpm --restore resets the modes and owners of a package's files; anything not from a package stays wrong. Reinstalling is often the more trustworthy route.
Things that look like 777 but are fine
- Symbolic links show as
lrwxrwxrwx. A link's own mode is not used; access is decided by the file it points to. /tmpis world-writable on purpose, but with the sticky bit: 1777, shown asdrwxrwxrwt. If you really need a directory everyone can write to, that is the mode to use.
777 compared with its neighbours
Questions
Is chmod 777 safe?
Not on anything shared or reachable from a network. It lets every account, including the ones your services run as, modify, replace or delete the target. It is tolerable for a scratch directory on a machine only you use. On a server, fix the owner or group and use 755 or 775.
How do I undo chmod -R 777?
chmod cannot reverse it, because the previous modes are not stored anywhere. For your own files, set directories back to 755 and files to 644 with find, then restore execute bits on scripts and tighter modes on secrets. If it was run on system directories, restore from a backup or reinstall: setuid programs such as sudo will have lost their special bits.
Why do I still get "Permission denied" after chmod 777?
Because the mode was not what blocked you. Check that every parent directory gives your user execute permission, that the file system is not mounted read-only or noexec, and whether SELinux or AppArmor is denying the access. On Linux, a file marked immutable with chattr +i cannot be changed whatever its mode.