Linux file and folder permissions management
Table of contents:
- Managing file and folder permissions in Linux
- User owner and group owner of a file
- Types of Permits
- Read permission
- Write permission
- Permission to execute
- How are permits granted?
- Change of permissions
As we know, Linux is a system that was designed with a network orientation. Therefore, security represents a critical point since the protection of the information we store on our computers or servers depends on it. It is here where the management of file and folder permissions in Linux becomes essential, since many users will have the possibility of access to all resources.
Managing file and folder permissions in Linux
User owner and group owner of a file
In Linux, all files necessarily belong to a user and a group of users. Therefore, when a file is created, the owner will be the user who created it and the group will also be the main group of the said user.
One way to view the user and group that owns a file is by using the ls command, followed by the -l (long format) option.
The result is a list of all files, one per line. Where, the first 10-character block at the beginning represents the file type and permissions (See image at the beginning).
The first character indicates the type of file. If it is a hyphen '-' it is a normal file, if it is one the “d” represents a folder (directory), on the other hand the letter 'l' indicates that it is a link. You could also refer to other values such as s, p, b that correspond respectively to sockets, pipes and block devices.
The next 9 characters represent the owner user permissions (3 characters), the owner group permissions (3 characters) and the permissions of the rest of the users (3 characters). Which are coded according to the letters relevant to each type of permit (we will see this in detail in the next section). If no letters appear and there are dashes instead, it means there is no permission type set.
Types of Permits
The management of file and folder permissions in Linux is done through a scheme of three types of permissions that users or groups can have. The scheme is as follows:
- Read permission Write permission Execution permission
Its meaning changes according to the context where it is applied, that is, if it is files or folders. We will see this in the sections below.
Read permission
This means that the user has permissions only to read or view the file. Applies for access from any application for editing files or console commands. In case the user does not have the permissions, they simply cannot see the file.
On the other hand, if a user has read permissions for a folder, it indicates that the user will be able to see all the contents of the folder.
In permission management, the letter “r” is used to represent the read permission, coming from the English “read”.
Write permission
This permission indicates that a user has power over a file to modify its content, even up to deleting it. It also gives you the ability to modify file permissions using the chmod command, as well as changing the owner (user or group), using chown.
In the case of folders, it gives the user the power to modify the content and perform actions such as creating and modifying other folders / files within it.
It is represented by the letter "w" the writing permission, comes from the English "write".
Permission to execute
As we can infer from its name, this permission grants the user the ability to execute a file. In case a user does not have execute permissions on a file, they will not be able to execute it even if it is an application. Furthermore, the only executable files are scripts or command files and applications; if we try to run them without possessing the permissions it will result in errors.
As for the folders, if the user has execute permissions on them, it refers to the fact of being able to access it. This permission applies both to enter from the cd command or from any file explorer.
The execution permission is represented by the letter "x" from the English "e X ecute".
You may be interested in reading: Managing users and groups in Linux
How are permits granted?
Permission management in Linux defines that permissions can only be granted as follows:
- To the user who owns the file To the group that owns the file To all other users on the system (all but the owner)
In other words, there is no possibility of giving permissions to specific users or unless you are the owner of the file. Therefore, permissions can only be assigned to the owning user, the owning group, or other users. Be it reading, writing, execution or a combination of them.
It is important to note that in order to make changes to permissions on a file, it is required to have execution permissions on it. On the other hand, the root user can make modifications, especially since he has full access to the system administration.
Change of permissions
In case you want to make changes in permission management, we use the chmod command. The chmod command syntax is as follows:
chmod permission filename_or_folder
Where "permission" is represented as follows:
Initials to whom the permission is addressed:
- user = group = gresto = o (other)
Followed by the sign corresponding to the action:
- Sign + to add permission Sign - to remove permission
Finally, the type of permission: read = r, write = w and execute = x
Let's see some examples with the file “example.txt”
Grant write permission to the owner user on the file “example.txt”:
chmod u + w example.txt
Eliminate the permission to write to other users on the file “example.txt”:
chmod ow example.txt
Grant read permission to the owning group on the file "example.txt":
chmod g + r example.txt
You can also grant different permissions in the same command execution, you only have to separate them with commas:
chmod u + w, gr, or example.txt
As it also allows to put several users together
chmod ug + w example.txt
On the other hand, there is also the possibility of changing the permissions by using the file explorer. For this, we just need to select the file or folder and clicking on the right mouse button -> Properties, the properties window will appear, then we will go to the permissions tab and we will be able to establish them in a simple and fast way. It should be noted that the selection can be one or more files or folders.
Linux basic permissions: ubuntu / debian with chmod
We explain in great detail how to manage permissions in Linux with the CHMOD command: debian, ubuntu, fedora, linux mint, elementary
▷ How to change folder permissions in windows 10
Learn how to change folder permissions in Windows 10 ✅ You can access and modify it. You will see how to assign user to shared folder
Best commands for linux: basic, administration, permissions ...
We bring you a list with the best commands for linux, where we will cover: permissions, basic, installers, main shortcuts and file comprehension.