Linux File permissions Explained

Linux file permissions play important role as it not only enhances security by ensuring that there is no unauthorized access to the files, making Linux file permissions as an important part of system’s security model. However the directory permissions work a bit differently than file permissions. Access control List ACL can also be used for managing file and directory permissions beyond the traditional user-group-other model.

There are three different permissions that are associated with the file.

  1. Read (r) – Person can read the file
  2. Write (w) – Person can edit the file
  3. Execute (x) – Person can execute the file

How Linux File Permission looks Like?

If you want to see the permissions associate with the file you can simply use the below command.

ls -l

The file permissions might look something like this.

-rw-rw-r--             1             user          group    0     Jan 31       12:57         test

“-rw-rw-r– ” defines the permissions user, group and others. Before deep diving into the concepts of the file permission you need to get an overview about owner, groups and others

Owner(user):

    The “owner” refers to the user who has created the file or directory. This user has specific privileges to set permissions for themselves, the group, and others. By default, the owner has more control over the file than other users. Ownership can be transferred by an administrator or the user themselves using appropriate commands.

    Group:

    The “group” refers to a set of users who are classified under a common name and share access rights. Each file or directory is associated with a specific group. Members of this group will have the permissions that the group is granted on the file or directory. This categorization is useful for managing access for multiple users who need similar permissions.

    Other:

    “Others” are all the users on the system who are neither the owner nor members of the group associated with the file. Permissions for others are generally more restrictive to maintain system security and ensure privacy. These permissions apply to anyone who can access the file system but does not have specific ownership or group privileges.

    Linux file permissions

      How to change the permissions

      The permission of the file can be changed via chmod command in two different ways

      Changing Linux file permissions in numeric code

      0
      1–x
      2-w-
      3-wx
      4r–
      5r-x
      6rw-
      7rwx
      chmod 755 filename

      This will set the following permissions

      1. User: can read, write and execute
      2. Group: can rad and execute the file
      3. Others: can read and execute the file

      Below is the basic example of how this can be done

      Linux file permissions change

      Changing file permissions through alphabetical option

      Change the Linux file permissions using chmod through below simple command

      chmod +rwx filename
      
      chmod -rwx filename

      To change the user(Owner) permissions

      u+rwxThis will allot read, write and execute permissions to the user
      u-rwxThis will remove read, write and execute permissions to the user
      u+rw,u-xThis will allow read and write and will disable the execute permission
      (Note that this is separated by comma)
      u+r,u-wxThis will allow user to read only and remove the other permission
      Example:
      chmod  u+rwx,u-x  filename

      To change the group permissions we can simple replace “u” with “g”

      g+rwxThis will allot read, write and execute permissions to the group
      g-rwxThis will remove read, write and execute permissions to the group
      g+rw,g-xThis will allow read and write and will disable the execute permission
      (Note that this is separated by comma)
      g+r,g-wxThis will allow group to read only and remove the other permission


      Permission can also be changed for other in the same way.

      o+rwxThis will allot read, write and execute permissions to the other
      o-rwxThis will remove read, write and execute permissions to the other
      o+rw,g-xThis will allow read and write and will disable the execute permission
      (Note that this is separated by comma)
      o+r,o-wxThis will allow other to read only and remove the other permission

      If you want to change the permission of users, groups and others at the same time it can be done via below command separated by comma. Through the combinations above you can assign any permission to the file.

      chmod u+rwx,g+rw,o+rw filename

      Linux file permissions are very important as they prevent the unauthorized access to the file if the permission are set accordingly. Additionally file access control list (FACL) can also be used to assign the permissions to the file.

      Thanks for reading the blog on Linux file permissions you can also visit our website if you want to know more about Linux.

      2 thoughts on “Linux File permissions Explained”

      Leave a Comment