How file permissions work in Linux (I)

linux file permissions

The file and directory permissions are an essential part in the world of GNU / Linux, and they constitute one of the parts that have been inherited from what had been present in Unix for years. For a significant number of users who have had to deal with the fact of reaching this platform at some point or another, it is one of those issues that blocks and imposes respect, but like everything in life it is simple to understand if we are gives the right help.

In this post we will try to clear up some doubts, and be as clear, basic and essential as possible so that everyone can begin to understand how file and directory permissions work in GNU / Linux. It is by no means an advanced guide, so those who already have experience in this topic can follow along, because we will try to be clear and detailed for those who are just starting out in this operating system, or those who despite having been using this platform for some time still do not have this well learned.

The first thing to understand is that permissions are divided into three groups: owner, group and others, which represent the Access permits which will have the owner of the file or directory, which will have a user that belongs to the group that owns that file or directory, and which will have the rest of the users of the system. To view these permissions we can go to any directory and execute the following:

Ls -l

We will see similar to what we have in the upper image of this post, where we have information represented in several rows and columns. The latter show us something like -rw-r – r– 1 root root 164 Nov 11 2014 xinitrc, and what we see well on the left is what will interest us the most to begin to understand how we can manage permissions. That first column shows us 10 spaces, each of them with a different meaning depending on whether it is occupied by:

  • b: block device
  • c: character device (for example / dev / tty1)
  • d: directory
  • l: symbolic link (for example / usr / bin / java -> / home / programs / java / jre / bin / java)
  • p: named pipe (for example / proc / 1 / maps)
  • - permission not assigned
  • r: reading
  • w: writing
  • x: execution

The d will only be present in the first space starting from the left, and it means that the element in question is a directory, so in case of having that space occupied with a dash «-» we will be in front of a file. Later, the next nine spaces are divided into three groups of three, and the order is always the following: rwx, which represents the write, read and execute permissions for the owner, the group and the others (others) respectively.

What follows is a number that shows us the number of links to this file or directory, a figure that is often 1, sometimes it can be 2 and a few, the least, it has another number. That does not matter for now, or at least it is not significant for our purpose of mastering file permissions in Linux, so let's move on to the next field since this does interest us since that 'root' that we see there means that he is owner of this file, and the 'root' that we see in the fourth column implies that the file also belongs to the group 'root'. Then the fields that follow represent the inode size, the date and the name of the file or directory.

With this information in mind we will be able to begin to understand what follows, which is the numeral nomenclature for permissions, something very typical of GNU / Linux, BSD and other * nix systems. In addition, this nomenclature will help us to change the file permissions quickly using the chmod command, and that is what we will see in another post but for now we can focus on the following: Read permission means that we can see the contents of said file or directory, writing means that we have permission to modify the file or directory and execution permission means that we can execute the file or, if we are in front of a directory, that we can search in it. (that is, do "ls"). This explains why the fundamental files in the system, such as / usr /, / usr / bin or / usr / lib have execute permission enabled but not write permission except for the owner, since this way all users can execute all the commands but do not modify or delete anything until we are given those permissions or become 'root' through the 'su' command.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Javier said

    Excellent note !! Greetings

  2.   Mara said

    I shit on the information!