DEV Community

Cover image for File Ownership and Permissions in Linux
Fazal ur Rehman
Fazal ur Rehman

Posted on • Updated on

File Ownership and Permissions in Linux

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, 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, you would know permission can be view by long listing -l option of the ls command, use this command to view.
Permissions
Notice that for each file listed, the first character either start with d or - (hyphen). This conveys the information either the file is a directory or a regular file, Other file types are giving below:

Permission table

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

Permission

The Permission group:

Each permission group contains a combination of these characters.

  • r : The Read permission gives the authority to open and read a file.
  • w : The Write permission gives the authority to write or modify the file.
  • x : The Execute permission gives the authority to run a file.
  • - : No permission.
  • Note that First character always represent read permission, second one write, and last execute. hyphen means no permission

    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.
    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.

    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
    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 :))

    Top comments (2)

    Collapse
     
    moopet profile image
    Ben Sinclair

    You mention that links can be hard or soft (symlinks) but I think it's important to clarify that the number displayed in ls is the number of hard links. You can symlink as many times as you like but it won't affect that number.

    Collapse
     
    iamfazal profile image
    Fazal ur Rehman

    Ooh, my bad!

    Thanks for reading :))