755 vs 644
Use 755 for directories and for files that are run as programs, and 644 for every other file. The only difference is the execute bit, which on a directory means "may enter it" and on a file means "may run it".
Side by side
chmod 755
chmod 755 = rwxr-xr-x: owner full access, everyone else read and execute.
| Read 4 | Write 2 | Execute 1 | Digit | |
|---|---|---|---|---|
| Owner (user) | 7 | |||
| Group | 5 | |||
| Others | 5 | |||
| Special | 0 |
7Owner (user): 7 = 4 read + 2 write + 1 execute5Group: 5 = 4 read + 1 execute5Others: 5 = 4 read + 1 execute
On a file
- Owner (user) read it, change it and run it as a program
- Group read it and run it as a program
- Others read it and run it as a program
On a directory
- Owner (user) list the names inside, enter it and open files by name, create and rename and delete entries
- Group list the names inside and enter it and open files by name
- Others list the names inside and enter it and open files by name
chmod 755 filechmod u=rwx,go=rx filels -l → -rwxr-xr-x
chmod 644
chmod 644 = rw-r--r--: owner read and write, everyone else read.
| Read 4 | Write 2 | Execute 1 | Digit | |
|---|---|---|---|---|
| Owner (user) | 6 | |||
| Group | 4 | |||
| Others | 4 | |||
| Special | 0 |
6Owner (user): 6 = 4 read + 2 write4Group: 4 = 4 read4Others: 4 = 4 read
On a file
- Owner (user) read it and change it
- Group read it
- Others read it
On a directory
- Owner (user) list the names inside; write without x does nothing useful (names only: without x the files cannot be opened or even stat'ed)
- Group list the names inside (names only: without x the files cannot be opened or even stat'ed)
- Others list the names inside (names only: without x the files cannot be opened or even stat'ed)
chmod 644 filechmod u=rw,go=r filels -l → -rw-r--r--
What to know
Both modes let only the owner write and let everyone read. 755 (rwxr-xr-x) adds execute for all three classes; 644 (rw-r--r--) has none.
For a website or project tree you usually want both at once: directories 755, files 644. chmod -R u=rwX,go=rX dir does that, keeping execute on files that already had it. The explicit form is find dir -type d -exec chmod 755 {} + followed by find dir -type f -exec chmod 644 {} +.
Gotchas
- 644 on a directory makes its files unreachable for group and others, even though they can list the names.
- 755 on data files is mostly harmless but sloppy: it shows up as noise in git (the executable bit is tracked) and lets the files be run if they happen to be scripts.
- The
findversion resets every file to 644, including scripts that need to stay executable. TheXversion does not.
Related explainers
- chmod 755 (rwxr-xr-x)chmod 755 gives the owner read, write and execute, and everyone else read and execute. When to use it for...
- chmod 644 (rw-r--r--)chmod 644 lets the owner read and write a file while everyone else can only read it. The default for...
- chmod X (capital X)Capital X in chmod adds execute only to directories and to files that already have an execute bit. Use it...
- umask 022umask 022 means new files are created 644 (rw-r--r--) and new directories 755 (rwxr-xr-x). How the umask...