...
Skip to main content
Print

Chmod Explained: File Permissions on Linux

With chmod you determine who may read, write or execute a file on Linux. The most commonly used values are 644 for files and 755 for folders. With chown you also determine who the owner is. Together they form the basis of a secure server.

How do file permissions work?

Every file has permissions for three groups: the owner, the group and everyone else. Per group there are three permissions:

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1

You add up the numbers per group. So 7 is read, write and execute (4 + 2 + 1) and 5 is read and execute (4 + 1).

Common values

chmodXITENS
chmod 755 map= owner everything, others read and open. Default for folders.
chmod 644 bestand= owner read and write, others read only. Default for files.
chmod 600 bestand= only the owner may read and write. For secret files such as SSH keys.
chmod +x script.sh= makes a script executable.

Note: never use 777. Then anyone can change your files.

Viewing permissions

ls -l

You then see for example -rw-r--r--. That means 644.

Changing the owner with chown

chown www-data:www-data /var/www/example.com -R

Correct permissions for a website

Set all folders to 755 and all files to 644 in one go:

find /var/www/example.com -type d -exec chmod 755 {} \;
find /var/www/example.com -type f -exec chmod 644 {} \;

Related articles

Table of Contents