Updated June 19, 2023
Introduction to Linux File Permissions
The following article provides an outline for Linux File Permissions. Linux is a multi-user operating system, i.e., many users can access it simultaneously. Therefore, it can be used in servers and mainframes without any need for modification. Linux has great security features, but being a multi-user operating system, it is prone to a security threat. Unsolicited users may corrupt, remove or change important data. So it is necessary to avoid a user accessing any other user’s confidential or crucial files and data. To implement this security, permission must be granted before the user can access the file. Here permission specifies what a particular user can or cannot do with respective files and directories. These permissions help to create a secure environment for the users.
Linux File Permission
Linux systems consist of a file control mechanism that determines who has the right to access a file and what steps or actions he/ she can perform on it. The file control mechanism has two components.
- Classes or Ownership: It refers to those who can access a particular file.
- Permissions: It refers to the actions that can be performed on the file by that particular user.
Classes or Ownership of Linux Files
There are three types of classes:
1. Owner or User
A person who creates a file is called a user or an owner of that particular file. User has no impact on the actions of other users. The ownership can be specifically transferred or granted to any other user also.
2. Group
A group can have multiple users. Every user belonging to a particular group would have the same privileges and access permissions for a particular file. A group does not affect the actions of other groups. For example, consider your team is making a project, and every member of your team need to access the file, so instead of granting permissions to every member individually, you can create a group of all team members and grant permission to the group, i.e., every member belonging to that group can access that file.
3. Others
It refers to all other users that can access the file. Setting permission for others refers to setting permission to the world. It refers to those who are not the owners or not in a group, i.e., the general public.
Permissions for Linux Files
For every file, three types of permissions are applicable to all classes.
1. Read (r): The read permission allows the user to open the file and read its contents. However, the user is not allowed to modify or change the file’s contents.
2. Write (w): The write permission allows the user to modify or change the file’s contents.
3. Execute (x): This permission allows the user to execute the program or the code. If a user lacks execution permissions, they can read or modify the code, but they will be unable to execute it.
Advanced Permissions
- _: No permission
- d: Directory
- l: The file is a symbolic link
- s: This indicates setuid/ setgid permissions. These permissions indicate to the system that an executable should run with the permissions of the owner.
- t: This refers to sticky bit permissions. These permissions restrict the renaming and deletion of a file, i.e., only the owner can delete or rename the particular file.
Examples
There are some cases for the permissions that are most frequent.
- rwx: This is the permission that allows the user to read, write, and execute the program. Execute permission is applicable only if the file is a program.
- rw-: This is the permission that allows the user to read and modify the file’s contents, but the user does not have the authority to execute it.
- r-x: This is the permission that allows the user to read and execute the program, but he has no authority to make modifications to the program code.
- r–: This permission allows the user only to read the file’s contents. He/ she is neither allowed to modify nor execute the file (in case it is a program).
Now lets us see how to read the permissions that appeared on the terminal.
The ls – l command gives the file type and access permissions related to a particular file.
The above screenshot depicts the file permissions.
- The first – depicts that a file is selected.
- Then there are nine characters: r refers to read permission, w refers to write permission, x refers to execute permission, and – refers to no permission.
- The first three characters depict the permission given to the owner. For example, in the above screenshot, rw- refers that the owner can read the file’s contents and change or modify the file but cannot execute it.
- The next three characters depict the permission given to the group. For example, in the above screenshot, rw- refers that the group members can read the file and modify or change the file but cannot execute the file.
- The last three characters depict the permission given to the world or other users. For example, in the above screenshot, r- – shows that other users can only read the file. They can neither modify nor execute the file or program.
Changing Security Permission
1. We can change the permission by using chmod.
Syntax:
chmod [permission] [path]
Example: chmod o+x abc.txt (here + shows adding and – shows the removal of permission)
2. We can also change multiple permissions at a time.
Example: chmod ugo-rwx abc.txt
Conclusion
In this article, we have discussed the file permissions in Linux. This is to be kept in mind that the security of files is important. Malicious users will target the files and try to change, remove or delete the file or its content. Setting permissions must be done carefully to ensure the smooth execution of tasks.
Recommended Articles
We hope that this EDUCBA information on “Linux File Permissions” was beneficial to you. You can view EDUCBA’s recommended articles for more information.