Learning The Basics of Permissions in Linux is Important

This entry is part 19 of 19 in the series Linux Basics For Hackers

Linux Basics For Hackers

Gather the URLs : Challenge 2

Permissions are the backbone of access control. You would never want anyone to have excess permissions to your private stuff, right? So, in this part, we are going to see what is meant by permissions in Linux. We will look at the different types of permissions available in the Linux environment, and when and why you should use them.




The String of Permissions in Linux

At first, understanding the permission rights might seem a little complex for you guys, but don’t worry, it’s not that complex. We are going to break them down into bits and bytes. In Linux, you are going to see a long string of characters something similar to this:

drw-r-xr-- # This is an example of apermission string

If you see clearly, there are in total 10 bits. Each bit here that you see converts into a specific permission. Let’s take a look at every one of them.

The First Bit

# The first bit
d 

The first bit of the permission set defines the type of file. In the above example, our first bit is represented as “d”. What this means is that the file for which we are seeing the permission is actually a directory. For a normal file, the first bit is represented as “-” (a dash). There are different types of files in Linux; some are driver files, and some files are also related to block devices, etc., and they have their own first bit.

I want you to go to your dev directory in your root folder and see it for yourself. There you will find multiple files where the first bit doesn’t make any sense (until you know its meaning 😂).

The User’s Permission Bits

After the first bit, the remaining 9 bits are for three different entities. Bits 2-4 are for user permissions. Now, what is meant by this? This just means that the user, who is the owner of the file has specific permissions; these permissions vary among read, write, and execute.

Let’s understand this with an example:

-rw-r--r--  # The user have read and write permissions but not execute
-rwxr--r--  # The user has read write and execute permission
-r--r--r--  # The user only have read permission

I think you got the idea right. The three permission bits are read, write, and execute; or, in short, we write them as rwx.

The Group’s Permission Bits

Now for the concept: again, we have three bits for group permissions. We are able to give read, write, and execute permissions to a group using these three bits. Bits 5-7 are for group permissions. Let us again look at it with an example:

-r---xr--  # The group have only execute permission
-r---w-r--  # The group have only write permission
-r--r-xr--  # Only read and execute permission

This is just the same as the user permission bits; the concept is similar. All that has changed is the position of the bits. For user permissions, we were using bits 2-4, but now for group permissions, we are using bits 5-7.

Other’s Permission Bits

We have seen permissions related to the user and the group. Now, anyone else who is accessing our Linux system and doesn’t belong to the specified user or group will have these permissions by default. These permissions are represented by the last three bits, i.e. bits 8-10. Let’s see it with an example again:

-r--r--rw-  # Any other user have only read and write permission
-r--r--rwx  # Any other user have all of the permissions i.e. read write and execute
-r--r--r-x  # Any other user have only read and execute permission

I think you have covered a lot in this part. These are all of the important topics that we needed to cover for a brief introduction to permissions in Linux. But before ending this part, let us just see some more examples in which permissions of the users, groups, and others are together.

The Complete Permissions String

Till now, you have seen the permissions separately for each entity individually. Let me give you some examples in which you will see the description of permissions for the whole permission string:

drwxrw--- # The file is a directory
# User's Permission : Read write and execute
# Group's Permission : Read and write
# Other's Permission : No permission ( This means any other user cannot perform any action on this file )

-rw--wxr-- # This is a normal file
# User's Permission : Read and write
# Group's Permission : Write and execute
# Other's Permission : Only read permission

lrwxrwx--x # This is a symbolic link file
# User's Permission : All permissions i.e. Read write and execute
# Group's Permission : All permissions i.e. Read write and execute
# Other's Permission : Only Execute permission

This was it for the basic understanding of permissions in Linux. If you want to know more about permissions in a little more detail and how you can alter them, you can check out the article below:

Linux File Permissions | Learn Now !!

That was it for this part; I’ll see you in the next one. I want you to learn about the chmod command by yourself. This is the command that you use for altering the permissions of a file. The above article explains this in more detail, so go check it out and start practicing.

Leave a Reply