chmod 644 (rw-r--r--)

The owner can read and write; everyone else can only read. It is what a new file gets by default, and the right mode for most files that are neither programs nor secrets.

Owner
Group
Others
Symbolic
Command

This tool runs in your browser. We never send what you type or paste to a server.

What chmod 644 sets

WhoDigitReadWriteExecuteSymbolic
Owner (u)6yesyesnorw-
Group (g)4yesnonor--
Others (o)4yesnonor--
chmod 644 file        # numeric
chmod u=rw,go=r file  # the same, in symbolic form

ls -l shows this mode as -rw-r--r-- on a file and drw-r--r-- on a directory. On a file, execute means it can be run as a program. On a directory, read lists the names inside, write creates, renames and deletes entries, and execute (search) is what lets you enter it and reach the files inside.

Why most files are 644

Programs ask for mode 666 when they create a file, and the system then removes the bits named in the process's umask. With the usual umask of 022, write is removed for the group and for others, leaving 644. Run umask in a shell to see yours. Both values are octal.

So you rarely need to set 644 by hand. You need it when putting things back: after an archive unpacked with odd modes, a copy from a Windows disk that made every file executable, or a careless chmod -R.

What belongs at 644, and what does not

  • Yes: website files (HTML, CSS, JavaScript, images, and PHP or Python source that an interpreter reads), documents, SSH public keys (id_ed25519.pub), and configuration with nothing confidential in it. /etc/passwd is the classic example: everyone may read it, only root may change it.
  • No, too open: anything containing a password, token or private key, such as .env or wp-config.php. Every local account can read a 644 file. Use 600, or 640 with a suitable group.
  • No, not enough: a script you run as ./script.sh, which needs the execute bit (755), and any directory.

644 on a directory breaks it

A directory without the execute bit cannot be entered by anyone, its owner included, and the files inside become unreachable whatever their own modes. This is the usual result of chmod -R 644 site: the shell answers "Permission denied" and the web server returns 403 for every page. Directories need 755. Put a tree right with:

find site -type d -exec chmod 755 {} \;      # directories first, one at a time
find site -type f -exec chmod 644 {} +        # then files

The first command ends in \; rather than + on purpose: each directory is repaired before find tries to look inside it. With + the changes are batched, and find is refused entry to the directories it has not fixed yet.

How safe is 644?

Only the owner can modify the file, so the questions are who the owner is and who can read it.

  • "Everyone" means every account and every service on the machine. On shared hosting that can include other customers.
  • A file is only as write-protected as its directory. If others can write to the directory, they can delete a 644 file and put their own in its place.
  • If the file is owned by the user a web application runs as, the application can rewrite it despite the tidy-looking mode. Code is better owned by a separate deploy user.

Checking and finding

stat -c '%a %n' index.html                   # GNU/Linux
stat -f '%Lp %N' index.html                  # macOS and BSD
find site -type f ! -perm 644                # files that are not exactly 644
find site -type f -perm -002                 # files that others can write to

644 compared with its neighbours

ModeSymbolicDifference from 644
664rw-rw-r--The group can write too: for files a team edits
600rw-------Nobody else can read: for secrets
444r--r--r--The owner cannot write either
755rwxr-xr-xAdds execute: for programs and directories

Questions

What is the difference between chmod 644 and 755?

The execute bits. 644 is for files that are read: pages, images, documents, configuration. 755 adds execute for everyone, which a file needs to be run as a program and a directory needs to be entered. The usual pairing is 644 for files and 755 for directories.

Why do I get 403 Forbidden when my files are 644?

The files are probably fine and a directory is not. The web server user needs the execute bit on every directory along the path to the file, so check that each one is 755 (or at least 711). The other common cause is a file whose "others" read bit is missing while the server is neither its owner nor in its group.

Should .env or wp-config.php be 644?

No. 644 lets every local account and every other service read the credentials in it. Use 600 if the application runs as the file's owner, or 640 with the group set to the one the application runs under.