chmod 644: The Default File Mode and When to Change It
644 is rw-r--r--: the owner can read and write, everyone else can only read. It is the default mode for a newly created file under the usual 022 umask and the right answer for most non executable files.
At a glance
- Octal
- 644, written 0644 in four digit form
- Symbolic
- u=rw,g=r,o=r
- On a file
- -rw-r--r--
- On a directory
- drw-r--r--, which cannot be entered because execute is missing
- Owner
- Read and write
- Group
- Read only
- Others
- Read only. Every local account can read the contents
In detail
644 is the file mode you should reach for by default. HTML, CSS, images, JSON, Markdown, source files, most things under /etc: all of them want read and write for the owner and read for everyone else. It is what a 022 umask produces, which is why the overwhelming majority of regular files on a typical system already have it.
Its partner is 755 on directories. A web root of 755 directories and 644 files is the standard layout, and it is what most hardening guides prescribe for static content. Keeping the two apart matters: applying 644 to directories makes them unenterable, and applying 755 to files marks documents as programs.
The clear case for changing it is a secret. Every local account can read a 644 file, so an environment file, a private key, a token or a database dump wants 600 if only the owner needs it, or 640 if a service group must read it as well. This is the single most common real mistake, and it usually reaches production through a deploy that copies files without setting modes.
The other case is an executable. A script at 644 gives permission denied when you try to run it even though it is perfectly readable, because the execute bit is missing. That is what chmod +x fixes, taking the file to 755 under a normal umask, and it is why a freshly written script never runs on the first attempt.
The calculator lists 0644 as a preset next to 0755, which is the fastest way to see the pairing. Toggle the owner execute checkbox and watch the octal move from 644 to 744 and the ls -l rendering from -rw-r--r-- to -rwxr--r--, which is what chmod u+x does.
Examples
chmod 644 index.html
chmod u=rw,g=r,o=r index.htmlfind /var/www/site -type d -exec chmod 755 {} +
find /var/www/site -type f -exec chmod 644 {} +
drwxr-xr-x /var/www/site/
-rw-r--r-- /var/www/site/index.html
-rw-r--r-- /var/www/site/style.css
Then tighten anything with a secret in it:
chmod 640 /var/www/site/.envThings that catch people out
- 644 on a script produces permission denied on execution. The file is readable, but without the execute bit the kernel will not run it.
- 644 means every account on the machine can read the file. On shared hosting that includes other customers' accounts, so it is never the right mode for an environment file or a key.
- 644 on a directory removes the execute bit and makes it impossible to enter, including for the owner. Directories want 755.
- Files uploaded over FTP or extracted from a ZIP archive often arrive with a different mode, because the archive carries its own permission bits or none at all. Set modes explicitly after extraction rather than assuming the umask applied.
Try it: Chmod Calculator
Tick the nine permission boxes, or type an octal or symbolic value, and get the three digit and four digit octal, the ls -l rendering and the exact chmod command back.
Chmod Calculator
LOCAL · Browser-OnlyCalculate Unix file permissions with an interactive chmod builder
Permission Matrix
| Entity | Read (4) | Write (2) | Execute (1) | Octal | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | rwx | |||
| Group (g) | 5 | r-x | |||
| Others (o) | 5 | r-x |
Special Bits
Advanced permission flags for executables and directories
Generated Permissions
755rwxr-xr-x-rwxr-xr-xchmod 755 filenamechmod u=rwx,g=rx,o=rx filenamePermission Breakdown
Owner (u)
7rwx- - Read files / list directory contents
- - Write / modify / delete
- - Execute / traverse directory
Group (g)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Others (o)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Common Permissions Reference
| Octal | Symbolic | Meaning |
|---|---|---|
777 | rwxrwxrwx | Full access for everyone |
755 | rwxr-xr-x | Owner full, others read and execute |
750 | rwxr-x--- | Owner full, group read and execute |
700 | rwx------ | Owner full access only |
666 | rw-rw-rw- | Read and write for everyone |
644 | rw-r--r-- | Owner read/write, others read only |
600 | rw------- | Owner read/write only |
555 | r-xr-xr-x | Read and execute for everyone |
444 | r--r--r-- | Read only for everyone |
400 | r-------- | Owner read only |
Related File permissions
All file permissions →chmod 755: The Standard Mode for Directories and Programs
755 gives the owner full control and everyone else read and execute. Why it is right for directories and executables and wrong for ordinary data files.
chmod 600: Owner Only Read and Write for Keys and Secrets
600 gives the owner read and write and nobody else anything. The mode SSH, PostgreSQL and other tools insist on for files holding credentials.
chmod 640: Configuration Files a Service Group Can Read
640 gives the owner read and write, the group read only, and everyone else nothing. The correct mode for configuration holding credentials.
chmod +x: Making a File Executable and the umask Catch
chmod +x adds the execute bit, but without a class it is masked by the umask. Why scripts also need read, and how to record the bit in version control.
chmod 622: Write Without Read, and the Old Terminal Mode
622 lets the owner read and write while the group and others can only write. Where this came from, what write without read really allows, and why it is rare.
chmod 555: Read and Execute With No Write for Anyone
555 removes the write bit from the owner as well as everyone else. What that protects against, what it does not, and how real immutability is done.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder
- htaccess Generator Free online htaccess generator - generate Apache .htaccess redirect and rewrite rules