1. What are file permissions
Every file or folder in Linux has access permissions. There are three types of permissions (what allowed to do with a file):
* read access
* write access
* execute access
Permissions are defined for three types of users:
* the owner of the file
* the group that the owner belongs to
* other users
Thus, Linux file permissions are nine bits of information (3 types x 3 type of users), each of them may have just one of two values: allowed or denied.
Simply put, for each file it can be specified who can read or write from/to the file. For programs or scripts it also can be set if they are allowed to be executed.
2. Textual representation like "-rwxr--r--"
It is used in Linux long directory listings. It consists of 10 characters. The first character shows the file type. Next 9 characters are permissions, consisting of three groups: owner, group, others. Each group consists of three symbols: rwx (in this order), if some permission is denied, then a dash "-" is used instead. Example:
-rwxr--r--
0123456789
* Symbol in the position 0 ("-")is the type of the file. It is either "d" if the item is a directory, or "l" if it is a link, or "-" if the item is a regular file.
* Symbols in positions 1 to 3 ("rwx") are permissions for the owner of the file.
* Symbols in positions 4 to 6 ("r--") are permissions for the group.
* Symbols in positions 7 to 9 ("r--") are permissions for others.
r Read access is allowed
w Write access is allowed
x Execute access is allowed
- Replaces "r", "w" or "x" if according access type is denied
3. Numeric (octal) representation like "644"
If a numeric representation is used (like in chmod command, for example), then it is in the octal format (with the base of
, and digits involved are 0 to 7. Octal format is used for the simplicity of understanding: every octal digit combines read, write and execute permissions together. Respective access rights for owner, group and others (in this order) are the last three digits of the numeric file permissions representation. Example: "0644". Here the second digit ("6" in the example) stands for rights of the owner, the third digit ("4" in the example) stands for rights of the group, the fourth digit ("4" in the example) stands for rights of others.
Octal digit | Text equivalent | Binary value | Meaning |
---|
0 | --- | 000 | All types of access are denied |
1 | --x | 001 | Execute access is allowed only |
2 | -w- | 010 | Write access is allowed only |
3 | -wx | 011 | Write and execute access are allowed |
4 | r-- | 100 | Read access is allowed only |
5 | r-x | 101 | Read and execute access are allowed |
6 | rw- | 110 | Read and write access are allowed |
7 | rwx | 111 | Everything is allowed |