subbing/24
Subbing › Guides › Linux file permissions

Linux file permissions

Read and write Linux permission modes: the three digits, rwx triplets, umask arithmetic, symbolic chmod, setuid, setgid and the sticky bit.

A mode is three digits, one each for the owner, the group and everyone else. Each digit is a sum: read is 4, write is 2, execute is 1.

Octal to rwx

755 is 7 = rwx, 5 = r-x, 5 = r-x: rwxr-xr-x. 644 is rw-r--r--. 600 is rw-------. Going the other way, add the values of the letters that are present.

umask

A umask lists the bits to remove from the default. New files default to 666 (no execute), new directories to 777. With umask 022, files become 644 and directories 755. With umask 077, only the owner keeps anything: 600 and 700.

Symbolic chmod

chmod g+w file adds write for the group; chmod o-rx file removes read and execute for others; a+x adds execute for all three. Only the named digit changes.

The fourth digit

A leading digit sets the special bits: 4 is setuid (run as the file's owner, shown as s in the owner execute slot), 2 is setgid (run as the group, or make new files in a directory inherit its group), 1 is the sticky bit (t in the others slot: only a file's owner may delete it, as on /tmp). chmod 4755 is a setuid executable.

Who can do what

Find the user's triplet. The owner uses the first, members of the file's group use the second, everyone else the third. A missing letter means no.

Start drilling linux permissionsGet the Android app

More on this topic: Linux permissions quiz, with sample questions and the full list of question types.