Skip to content

chmod 666

chmod 666 sets rw-rw-rw-: the owner, the group and every other account can read and write the file, and no one can execute it.

Permission matrix

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

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 and modifyList names only; write does nothing without execute
Group (g)Read and modifyList names only; write does nothing without execute
Others (o)Read and modifyList names only; write does nothing without execute

Facts

Representations of this mode
Octal666 (0666)
Symbolicrw-rw-rw-
ls -l, file-rw-rw-rw-
ls -l, directorydrw-rw-rw-
Equivalent symbolic commandchmod a=rw
Default umask that creates itumask 000 for new files
How Git records a file with it100644 (not executable)
Special bitsNone

When to use it

  • Device nodes every process must be able to open for writing: /dev/null, /dev/zero and /dev/tty are crw-rw-rw- on Linux. The kernel, not the file, decides what writing does there.
  • It is the mode new files get under umask 000, since programs create files with 666 and the umask removes nothing.

When not to use it

  • Regular files on any shared or internet-facing machine: any account or compromised service can rewrite configs, logs or templates. A writable PHP or template file is remote code execution waiting to happen.
  • Log files: any user can erase their tracks or inject fake entries. Use 640 with an adm or log group.
  • As a quick fix for a service that cannot write a file: make the service account the owner or a group member and use 664 or 660.

Commands

Set it on one file or directory
chmod 666 notes.txt
chmod a=rw notes.txt   # same result
Check the result
stat -c '%a %A %n' notes.txt     # Linux (GNU stat): 666 -rw-rw-rw-
stat -f '%Lp %Sp %N' notes.txt   # macOS and BSD

Applying it to a whole tree

Avoid chmod -R 666: it removes execute from every directory, so nobody but root can enter them, and makes every file world-writable. To repair a tree that got it, use the find commands below.

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 100644; 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

What does chmod 666 mean?
Owner 6 (read 4 + write 2), group 6, others 6. Everyone can read and write; nobody has execute.
Why is /dev/null 666?
Every program, whatever user it runs as, must be able to write to /dev/null to discard output. It is a character device, so the permission controls who may open it, and writes to it are simply dropped.
Can others delete a 666 file?
Deleting depends on the directory, not the file. In a 755 directory only the directory's owner can delete it, but anyone can empty it with a write such as : > notes.txt.

Last reviewed by Arielton Oberek.