Linux Permission

Mhd Omar Bahra
2 min readDec 6, 2020

I know that it’s frustrating to understand user permission in Linux, in this article I will be trying to simplify it as much as possible.

First of All, let’s take a look at an image that you can obtain by running this command:

ls -l

ls -l

permission | user |group |filesize | DateTime |filename

let’s take -rw-rw-r-- as an example of permission:

first thing you need to know is, why some permissions start with ‘d’ and others start with ‘-’, the difference, if it’s a directory then it starts with ‘d’, but if it is a file it starts with ‘-’.

Now let’s talk about rw-, first 3 characters represent the permissions of the user, second 3 characters represent the permissions of the group and the last 3 characters represent the permissions of others (which are neither in the group nor the owner).

r stands for ‘read’

w stands for ‘write’

x stands for ‘execute’

So basically -rw-rw-r--is telling us that, the user who owns the file has permission to read and write the file, and the group has permissions to read and write as well, however, others have the permissions only to read.

Think of these groups as the following:

u stands for user

g stands for group

o stands for others

let’s say now we want to give the owner of the file, in other words, the ‘user’ the permission to execute, this can simply be achieved by running this command:

chmod u+x filename/dirname

if you want to take this permission back, you can simply run:

chmod u-x filename/dirname

In this case, we used this to change the permission for the user only, if we wanted to change the permission for the group, we can simply change u with g, and o for others, however, let’s assume that we want to change the permissions of all groups for a certain file, it is not nice to write a single command for each file, instead, we can do it with one command.

for doing this, we need first to learn these:

0 means ‘no permission’

1 means ‘execute’

2 means ‘write’

4 means ‘read’

so let’s say we want to give the user the permission to read, write and execute, but we want to give the group permission of reading and writing, and we want to give others to permission only to read, this can be easily achieved by typing this command:

chmod 764 filename/dirname

where did 7 and 6 come from?

7 is the sum of 1+2+4 which according to the above list is ‘execute + write + read’ respectively.

6 is the sum of 2+4 which is ‘write + read’ respectively, thus by using summation we can give all of ‘user, group and others’ a permission.

--

--

Mhd Omar Bahra

I am a Software Engineer interested in Software Architecture and Quality Assurance.