chmod 644 gives the owner read and write, and everyone else read only: rw-r--r--. It is the standard mode for ordinary files. The tool’s view of it:
Octal 644
Symbolic rw-r--r-- (ls -l: -rw-r--r--)
Command chmod 644 file
owner 6 read write
group 4 read
others 4 read
Open it in the chmod calculator to change a digit and watch the symbolic form change.
Why 644 is the default for files
Most files should be readable by whoever needs to use them, and editable by only one person. With the usual umask 022, new files are created as 644 and new folders as 755. The missing execute bit is intentional: a data file, an image or a source file is never run directly, so it should not be marked as a program.
Where it fits
- Web content: HTML, CSS, JavaScript, images, and PHP files that the web server reads. The server only needs the read bit.
- Configuration that is not secret:
/etc/hosts,nginx.conf, a.gitconfig. - Source code and documents in a shared checkout.
Where it is too open
Anything with a secret in it must not be world-readable:
- SSH private keys, API tokens,
.envfiles, database password files: use 600. - Backups and dumps that contain customer data.
- Logs that may contain tokens or personal data.
SSH will not even try a key that other users can read: Permissions 0644 for 'id_ed25519' are too open. The cure is chmod 600 ~/.ssh/id_ed25519.
Where it is too closed
If the web server cannot read a file it will answer 403 Forbidden or a 500. A file at 640 belonging to the wrong group, or a folder missing the execute bit, produces the same symptoms; namei -l /path/to/file lists the mode of every folder on the way. When several people edit the same files, use 664 with a shared group.
Setting it
chmod 644 index.html
chmod u=rw,go=r index.html # the same, written symbolically
chmod -x script.sh # remove the execute bit from every class
Never apply chmod -R 644 to a tree: the folders lose their execute bit and become unusable. Use the two-step find from the 755 page instead.
Frequently asked questions
What does chmod 644 mean?
The owner can read and write (6), the group can read (4), and everyone else can read (4). In ls -l it is rw-r--r--. Nobody can run the file as a program, because there is no execute bit.
Is 644 the right mode for a PHP or HTML file on a web server?
Yes. The web server needs to read the file, and the owner needs to edit it. PHP files run through the interpreter and do not need the execute bit.
Why did ssh refuse my key with 'Permissions 0644 are too open'?
A private key must be readable by you only. 644 lets every user on the machine read it, so ssh refuses to use it. Use chmod 600.
How do I make all files 644 and all folders 755?
Use find: find . -type f -exec chmod 644 {} + and find . -type d -exec chmod 755 {} +. A single chmod -R cannot give the two kinds different modes.
More in this reference
- chmod 400: read-only private files, such as .pem keys
- chmod 600: private files for SSH keys, .env and other secrets
- chmod 664: files that a group can edit (rw-rw-r--)
- chmod 700: private folders and scripts that only the owner can use
- chmod 755: what rwxr-xr-x means and when to use it
- chmod 775: shared folders and scripts for a group (rwxrwxr-x)
- chmod 777: why it is dangerous and what to do instead