breakitdown

chmod 777 (rwxrwxrwx)

Answer

chmod 777 sets rwxrwxrwx: every user on the machine, including the web server and any compromised service, can read, modify, replace and execute the file. It makes permission errors go away by removing permissions entirely, which is why it is almost never the right fix.

Try

chmod 777 = rwxrwxrwx: everyone full access.

Read 4Write 2Execute 1Digit
Owner (user)7
Group7
Others7
Special0
  1. 7
    Owner (user): 7 = 4 read + 2 write + 1 execute
  2. 7
    Group: 7 = 4 read + 2 write + 1 execute
  3. 7
    Others: 7 = 4 read + 2 write + 1 execute

World-writable: every user on the system can change this. Almost never what you want, except /tmp-style directories, which also set the sticky bit (1777).

On a file

  • Owner (user) read it, change it and run it as a program
  • Group read it, change it and run it as a program
  • Others read it, change it and run it as a program

On a directory

  • Owner (user) list the names inside, enter it and open files by name, create and rename and delete entries
  • Group list the names inside, enter it and open files by name, create and rename and delete entries
  • Others list the names inside, enter it and open files by name, create and rename and delete entries

chmod 777 filechmod a=rwx filels -l → -rwxrwxrwx

What to know

A permission error means one specific user (for example www-data, nginx, or the UID a container runs as) needs one specific kind of access. 777 grants every kind of access to every user instead of that one.

The better fix is to make that user the owner or a member of the file's group, then grant only what it needs: chown www-data uploads/ with 755, or a shared group with 775 and 664. For Docker bind mounts, make the container run as the UID that owns the host directory (--user) instead of opening the directory to everyone.

On a directory, 777 also lets any user delete or rename other users' files in it. The one place world-writable directories are normal, /tmp, adds the sticky bit to prevent that: see 1777.

Where it fits

Gotchas

Related explainers

← chmod calculator