Skip to content

chmod 777

chmod 777 sets rwxrwxrwx: the owner, the group and every other account on the machine can read, modify and execute the file, or list, create and delete entries in the directory.

Permission matrix

Which permission bits each class has
WhoRead (4)Write (2)Execute (1)Digit
Owner (u)YesYesYes7
Group (g)YesYesYes7
Others (o)YesYesYes7

Execute means different things by type. On a file it lets the kernel run it as a program. On a directory it is search permission: entering it (cd) and reaching the files inside by name. Read on a directory only lists names.

What each class can do with a file and with a directory
WhoOn a fileOn a directory
Owner (u)Read, modify and runList, enter, create, delete and rename entries
Group (g)Read, modify and runList, enter, create, delete and rename entries
Others (o)Read, modify and runList, enter, create, delete and rename entries

Facts

Representations of this mode
Octal777 (0777)
Symbolicrwxrwxrwx
ls -l, file-rwxrwxrwx
ls -l, directorydrwxrwxrwx
Equivalent symbolic commandchmod a=rwx
Default umask that creates itumask 000 for new directories
How Git records a file with it100755 (executable)
Special bitsNone

When to use it

  • Throwaway directories on a single-user machine or inside a disposable container, where no other account exists to abuse the access.
  • For a minute, to prove that an error really is a permissions problem. Then revert to the narrowest mode that works.

When not to use it

  • Web roots and upload directories. Any process on the server, including a compromised script from another site on shared hosting, can drop or rewrite your files. The WordPress hardening guide says no directory should ever be 777, not even uploads.
  • Shared directories without the sticky bit: every user can delete or rename everyone else's files. Use 1777 (the /tmp mode) or a shared group with 2775.
  • Anything under ~/.ssh. ssh ignores private keys that others can access, and sshd with StrictModes (the default) refuses logins when your home, ~/.ssh or authorized_keys is writable by others.

Why 777 makes the error go away, and the real fix

When a web app cannot write to a directory, 777 appears to fix it because it grants write to the others class, which includes whatever account the web server or PHP-FPM runs as (www-data on Debian and Ubuntu, nginx or apache on Fedora and RHEL). It also grants the same write to every other account on the machine.

Give the access to that one account instead: make it the owner, or put it and your deploy user in a shared group and use 775 for directories and 664 for files.

ps -o user= -C nginx,php-fpm,apache2,httpd | sort -u   # who the server runs as
sudo chown -R www-data:www-data /var/www/site/uploads
sudo chmod 755 /var/www/site/uploads

Commands

Set it on one file or directory
chmod 777 shared
chmod a=rwx shared   # same result
Check the result
stat -c '%a %A %n' shared     # Linux (GNU stat): 777 drwxrwxrwx
stat -f '%Lp %Sp %N' shared   # macOS and BSD

Applying it to a whole tree

Do not run chmod -R 777. It makes every file in the tree writable and executable by every account. If it already happened, restore a sane baseline with the two find commands below, then add execute back only to the scripts that need it.

Reset a tree to the 755 / 644 baseline
find . -type d -exec chmod 755 {} +
find . -type f -exec chmod 644 {} +

Git and the execute bit

Git stores only one permission fact per file: 100755 if the owner execute bit is set, 100644 otherwise. A file with this mode is committed as 100755; the group and others bits never reach the repository. On Windows, or where core.fileMode is false, set the bit with git update-index --chmod=+x.

Frequently asked questions

Is chmod 777 safe?
Only where no untrusted account or process can reach the path. On a multi-user system or a web server it lets any account modify or replace the files, so a compromise of any other service becomes a compromise of yours.
What does chmod 777 do to a directory?
Anyone can list it, enter it, and create, delete or rename any file in it, including other users' files, because deleting a file depends on the directory's write bit, not the file's. Adding the sticky bit (chmod 1777) limits deletion to each file's owner.
How do I undo chmod -R 777?
Reset directories and files separately: find . -type d -exec chmod 755 {} + and find . -type f -exec chmod 644 {} +. Then restore execute on the few scripts that need it with chmod +x.
Is chmod 777 the same as chmod a+rwx?
The nine permission bits end up identical. The difference is that the numeric 777 also clears setuid, setgid and sticky on regular files, while a+rwx leaves those special bits as they were.

Last reviewed by Arielton Oberek.