DEV Community

loading...
Cover image for Permissions in Linux System

Permissions in Linux System

yashsugandh profile image yash sugandh Updated on ・4 min read

In the last post, we explored Controlling Processes in Linux System where we explored how to control processes running in our System.

Today we are going to explore one of the most important topics in the Linux System: Permissions.

What are permissions and why should we know about them?

Our Linux Systems are built on top of the Unix system, so they are not just multitasking but also a multi-user system.

This is not something that has been recently introduced but has been deeply embedded in the Linux systems from the early days.

What does a multi-user system mean?

In a multi-user system, more than one person can be using the computer at the same time.

For example, if you are connected to the internet, the remote users can access your system using Secure Shell(ssh).

Okay, this feature provide users with great power to login from anywhere.

To quote a great man:

With Great POWER comes Great Responsibility

Sorry just could not miss the opportunity to say this 😁

Okay let's get back to the topic since multiple users can log in into the same system along with a malicious user, how can you make sure that your files are secure?

This is where Permissions comes into the picture.

Permissions are divided into two major parts:

  1. Ownership
  2. Access Rights

1. Ownership
Files and directories in the Linux system is assigned 3 types of owner

  • Owner (the user who created the file/directory)
  • Group (to which the owner belongs to)
  • Others (all other users)

2. Access Rights
Files and directories in the Linux system have 3 access rights defined for all the 3 owners discussed above.

  • Read access denoted by r
  • Write access denoted by w
  • Execution access denoted by x

Okay so we have just found the answer what are Permissions and why should we know about them.

Now, the next question that comes into our mind is how can we check Permissions for a file or directory?

There are two easy ways we can check for Permissions on a file/directory

1. Using the UI

Let's start with the human-readable way

To check Permissions for a file/directory all we need to do is

  • Right-click on a file
  • Select properties from the menu
  • There we have 4 tabs Basic, Permissions Open with and Image(Type of file)

properties-UI

  • Select the Permissions tab

After selecting Permissions we see the following data

Properties-Permissions

In the above image,

  • Owner has a value of me since I was the one who created the file
  • Access provided for Owner is read and write

  • Group has a value of yash since that is my username

  • Access for the group is also read and write

  • Others have read-only access.

To change Permissions, the user can open the drop-down menu for each category and choose the desired permission.

Aren't we missing something? Where is the execution access?

If we look below the Access of others we can see that there is another field name Execute.

Execute allows us to check whether this file is executable or not and since in the above image checkbox is not ticked we can say that the file is not executable.

2. Using our Terminal

To find Permissions for files all we need to do is use ls command along with -l option.

terminal-all-permissions

In the above example, we used the command ls -l to list all the files and directories along with Permissions.

But to understand how to read Permissions better let's take an example of a single file

file-permissions

In the above example, we used the command ls -l I_O\ Redirection\ In\ Linux\ System.png to find the permissions for the respective files

In the Output -rw-rw-r-- 1 yash yash 75880 the first 10 letters are file attributes

The first letter describes the type of file, most common file types are

- specifies a regular file
d specifies a directory
l describes a symbolic link

After the type of file, we have the rest of 9 characters to describe access permissions i.e. rwx( read, write and execute).

In the above example, we have

rw - Read and Write for Owner
rw - Read and Write for Group
r - Read Only for all the Others

Similarly, we can have many different combinations of Permissions. Let's look at a few

File Attributes The Meaning of Attributes
-rw-rw-r-- A regular file that is readable and writable for Owner and Group but only readable for others
drw-r-r-- A directory that is readable and writable only for Owner and for Group and Others it's only readable
-rwx------ A regular file that is readable, writable, and executable by the Owner. No one else has any access.
-rwxr-xr-x A regular file that is readable, writable, and executable by the Owner. The file can only be read and executed by everybody else.

So, this is how we can read Permissions for a file/directory.

This is it for this post. In the next post, we will explore how to add/edit these permissions from Terminal.

See you in the funny papers 🚀

Discussion (3)

Collapse
allericksha profile image
Sunil Vijay

Hello yash, thanks for your write up. I would recommend this series for any noob who is surfing to learn linux. Such a beautiful contents. 👍🏻💯

Collapse
yashsugandh profile image
yash sugandh Author

@sunilVijay Glad you liked it!

Forem Open with the Forem app