breakitdown

755 vs 644

Answer

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

755644
Symbolicrwxr-xr-xrw-r--r--
Owner (user)rwxrw-
Groupr-xr--
Othersr-xr--

chmod 755

chmod 755 = rwxr-xr-x: owner full access, everyone else read and execute.

Read 4Write 2Execute 1Digit
Owner (user)7
Group5
Others5
Special0
  1. 7
    Owner (user): 7 = 4 read + 2 write + 1 execute
  2. 5
    Group: 5 = 4 read + 1 execute
  3. 5
    Others: 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 4Write 2Execute 1Digit
Owner (user)6
Group4
Others4
Special0
  1. 6
    Owner (user): 6 = 4 read + 2 write
  2. 4
    Group: 4 = 4 read
  3. 4
    Others: 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

Related explainers

← chmod calculator