Who can do what
| Class | Read (4) | Write (2) | Execute (1) | On a directory |
|---|---|---|---|---|
| Owner (u) | Yes | Yes | No | List the file names, but not open them. |
| Group (g) | Yes | No | No | List the file names, but not open them. |
| Others (o) | Yes | No | No | List the file names, but not open them. |
When to use chmod 644
Lets the owner read and write, and everyone else only read. It is the standard mode for regular files: documents, configuration, HTML, CSS and images.
Safe for anything that may be public. For files that hold secrets, such as .env files or private keys, use 600 or 640.
Commands
Set the mode with octal digits, or with the equivalent symbolic form:
chmod 644 path/to/file
chmod u=rw,g=r,o=r path/to/fileTo apply it to every directory below a folder (and not to the files), combine it with find:
find path/to/folder -type d -exec chmod 644 {} +chmod -R 644 changes files and directories alike, which is rarely what you want: directories usually need execute, regular files usually should not have it.