File Ownership and Permissions in Linux
Tags: linux, beginners, permissions, filesystem
Published: 2021-01-12 04:54:22

After getting a positive response and awesome feedback on my first article I'm very excited to share my second one

In this read, I will cover file permission and ownership, as I have already discussed in my previous article [power of ls command](https://dev.to/iamfazal/power-of-ls-command-2hja), that this is a very important corner of Linux. In addition, the concept of file and directory permissions, user and user group will be explored.

#Introduction
File ownership is critical for file security. Every file has some permissions, a single user owner, and a group owner. Understanding this core is very interesting and also very crucial when you are working on a distributed Linux based system. one important vulnerability exists when local access is granted, *Eg: write permission is assigned to user or group while you are assigning only read permission*

If you have read my previous article [power of ls command](https://dev.to/iamfazal/power-of-ls-command-2hja), you would know permission can be view by long listing <code>-l</code> option of the <code>ls</code> command, use this command to view.
![Permissions](https://dev-to-uploads.s3.amazonaws.com/i/bdsj981z08t1r1mqs26u.png) 
Notice that for each file listed, the first character either start with <code>*d*</code> or <code> - </code>*(hyphen)*. This conveys the information either the file is a directory or a regular file, Other file types are giving below:

![Permission table](https://dev-to-uploads.s3.amazonaws.com/i/eh11aa71exb8efmyhy0b.png)

The next highlighted nine characters are three group permission for three different types of owners.

![Permission](https://dev-to-uploads.s3.amazonaws.com/i/5e3dr68b6sbftp9v2bxp.png)
###The Permission group:
Each permission group contains a combination of these characters.
<li> <code>r :</code> The *Read* permission gives the authority to open and read a file. </li><li> <code>w :</code> The *Write* permission gives the authority to write or modify the file.</li><li> <code>x :</code> The *Execute* permission gives the authority to run a file.</li><li> <code>- :</code> No permission.</li>*<sub>Note that First character always represent read permission, second one write, and last execute. hyphen means no permission</sub>*
###Ownership:
####User:
A user is the owner of the file. By default, the person who creates a file becomes its owner. The first set of three characters is for the owner permissions.
####Group:
A group can contain multiple users. The most common reason to create a group is to provide a way for users to share files. For example, if several people work together on the same project and need to be able to collaborate on documents stored in files for the project. In this scenario, the administrator can make these people members of a common group, change the directory ownership to the new group, and set permissions on the directory that allows members of the group to access the files. All users that belong to the same group will have the same permissions to the files or directories. The second set of three characters is for group permission.
<sub>Eg: If the login user doesn't have permission to access the file, But the user belongs to the group that has permission then he/she can easily access it.<sub>
####Other:
Other includes all users that are neither the owner nor any group member who could own the file. In short, the whole world can have accessibility. The last three characters are for them.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9il92axvvzmgd16133pf.png) 
The permission block is succeeded by an integer. This integer is a *hard* link counter, Indicates how many files are linked to this file. There are two types of links in Linux file systems *hard* and *soft*. The difference between them is significant. It is because the way in which they work is totally different but both provide multiple directory entries (or references) to a single file. After link count, you see the user owner, the group owner, the file size, the date/time the file was last modified, and the last filename.


I hope this informative blog was helpful to you. Did you find it beneficial? Don’t forget to like and share. See more by following me and keep yourself informed of my next upcoming blogs.

*~ let me know in comments if you want me to write an article on soft and hard links, I will happily do it*.

Thanks! happy coding :))