Reading ls -l
ls -l /var/www/site
-rw-r----- 1 deploy www-data 1532 Nov 30 10:12 config.php
drwxr-xr-x 2 deploy www-data 4096 Nov 30 10:12 publicThe first ten characters decode like this, taking -rw-r----- as the example:
- Character 1, type:
-a regular file,da directory,la symbolic link. - Characters 2 to 4, owner:
rw-, so deploy may read and write. - Characters 5 to 7, group:
r--, so members of www-data may read. - Characters 8 to 10, others:
---, so everyone else gets nothing.
The two names after the link count are the owner and the group.
Read, Write, and Execute
| Bit | On a file | On a directory |
|---|---|---|
r | Read the content | List the names |
w | Change the content | Create, delete, rename |
x | Run as a program | Enter and reach files |
On a directory, w works only together with x. Deleting a file depends on the directory's permissions, not the file's.
Numeric Notation
Each set is a sum: read is 4, write is 2, execute is 1. Three digits give owner, group, and others.
| Mode | String | Typical use |
|---|---|---|
644 | rw- | Ordinary files |
755 | rwxr- | Directories, scripts |
640 | rw- | Config for one group |
600 | rw- | Private keys |
700 | rwx- | Private directories |
Changing Owner and Permissions
sudo chown deploy:www-data config.php
chmod 640 config.php
chmod g+w uploads
chmod o-r notes.txtThe owner and group are changed with chown, explained in the chown command guide. Modes are changed with chmod, either as numbers or as letters such as g+w; see the chmod command. Never use 777 to make an error go away; chmod 777 explains why.
Defaults and the umask
Most programs create new files with 666 and new directories with 777, and the kernel removes the bits set in the umask. With the common umask of 022, files get 644 and directories 755. How to read and change it is in umask in Linux.
Special Bits and ACLs
- Special bits: setuid, setgid, and the sticky bit add a fourth digit in front, as in
1777on/tmp. See sticky bit, SUID, and SGID. - ACLs: when owner, group, and others are not enough, access control lists give extra users or groups their own rights. A
+after the permission string inls -lshows an ACL. See setfacl and getfacl.
Root Is Not Held Back
The root user can read and write any file whatever its mode. The only limit is execute: root can run a file only if at least one execute bit is set. Permissions protect users from each other, not from root, which is why services should not run as root.
Safe Values on a Server
- Web files: 644 for files and 755 for directories, owned by the deploy user, with the web server's group able to read.
- Upload folders: writable by the web server's group only where the application must write, such as 775 on that folder alone.
- Config files with secrets: 640 with the application's group, or 600 when only the owner reads them.
- SSH: 700 on
~/.ssh, 600 on private keys andauthorized_. The ssh client ignores a private key that others can access, and with its default StrictModes setting the SSH server refuses key logins when the home directory,keys ~/.ssh, orauthorized_is writable by others.keys
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations