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
| Who | Read (4) | Write (2) | Execute (1) | Digit |
|---|---|---|---|---|
| Owner (u) | Yes | Yes | No | 6 |
| Group (g) | Yes | Yes | No | 6 |
| Others (o) | Yes | Yes | No | 6 |
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.
| Who | On a file | On a directory |
|---|---|---|
| Owner (u) | Read and modify | List names only; write does nothing without execute |
| Group (g) | Read and modify | List names only; write does nothing without execute |
| Others (o) | Read and modify | List names only; write does nothing without execute |
Facts
| Octal | 666 (0666) |
|---|---|
| Symbolic | rw-rw-rw- |
| ls -l, file | -rw-rw-rw- |
| ls -l, directory | drw-rw-rw- |
| Equivalent symbolic command | chmod a=rw |
| Default umask that creates it | umask 000 for new files |
| How Git records a file with it | 100644 (not executable) |
| Special bits | None |
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
chmod 666 notes.txt
chmod a=rw notes.txt # same resultstat -c '%a %A %n' notes.txt # Linux (GNU stat): 666 -rw-rw-rw-
stat -f '%Lp %Sp %N' notes.txt # macOS and BSDApplying 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.
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.