NB: This tutorial has worked on Centos 6,7,8 and 9
There are two types of permissions on Linux which include standard and extended or special permissions. This tutorial focuses on standard permissions.
Linux standard permissions, also known as file permissions, dictate how files and directories can be accessed and modified by users and groups. These permissions are an essential part of Linux's security model. There are three primary types of permissions: read, write, and execute, and these permissions can be assigned to three entities: the file owner, the group owner, and others.
Permissions are represented by a series of letters or symbols. You can use this table below as a Standard Linux Permissions cheat sheet or chart:
Permission | letter representation | Numerical or Octal Representation |
---|---|---|
Read | r | 4 |
Write | w | 2 |
Execute | x | 1 |
The first three characters represent the owner's permissions.
The next three characters represent the group's permissions.
The last three characters represent others' permissions.
For instance, in the permission string -rw-r--r--, the file owner has read and write permissions, the group owner has read permission only, and others have read permission only.
You can modify permissions using the chmod command in Linux, which allows you to add or remove specific permissions for the owner, group, and others. This can also be represented as 644 where 6 is (rw )or 4+2 and 4 is (r--). For octal, note that we are adding for all the three i.e, the user, group and others in a single command.
chmod u+x example.txt # Adds execute permission to the file for the owner
chmod g-w example.txt # Removes write permission for the group
chmod o+r example.txt # Adds read permission for others
I use the command “ls -l” to give a long listing so that I can see the permissions for the files in the directory.
The example.txt file has read,write and execute for the user, and only read for the group and others
I then change the permissions to 644 which represents (-rw-r—r--). Changing Linux permssions using numbers (octal) allows us to set the user, group and others all in one line.
We can see that the file permissions change accordingly. 644 is (-rw-r--r--) where 6 is (r+w) or (4+2),4 is (r) and 4 is (r).
We can add an rwx on all the three by giving 777. Each 7 is (rwx) when we add (4+2+1).
Here I remove the execute permissions to the user, group and others. The minus (-) was used.
We can see that the file has no execute on any of the three.
Here I add execute Linux permission to the user only.
We can see that only the user has an execute permission added.