How chmod numbers work
Add up the permissions for each group of people: read = 4, write = 2, execute = 1. Write the three sums in order: owner, group, others.
Example
chmod 640 notes.txt: the owner can read and write (6), the group can read (4), and others can’t open it (0).
Frequently asked questions
What does chmod 755 mean?
Each digit is one group of people: the owner, the file's group, and everyone else. Each digit adds up read (4), write (2) and execute (1). 7 = 4 + 2 + 1, so the owner can read, write and run it; 5 = 4 + 1, so the group and others can read and run it but not change it.
Which permissions should I use?
Usually 644 for files (owner can edit, everyone can read) and 755 for folders and scripts (folders need execute to be opened). Use 600 for private files like SSH keys and 700 for private folders. Avoid 777: it lets anyone change the file.
What are setuid, setgid and the sticky bit?
Special permissions, shown as a fourth digit in front. setuid (4) runs a program as its owner, setgid (2) runs it as its group or makes new files in a folder inherit the folder's group, and the sticky bit (1) on a folder like /tmp means only a file's owner can delete it.
What does the symbolic form like rwxr-xr-x mean?
Three letters for each of owner, group and others: r for read, w for write, x for execute, and a dash where the permission is missing. ls -l shows permissions this way.