We will check how many permissions are there and how you can change permissions accordingly. With Linux, you will get two different levels of authorization that include ownership and permission. We will see how different ownership and permission will work for Linux users.
Ownership of Linux Files
The Linux system handles three different types of owners for files and directories. These are users, groups, and others. First, we will see how permissions vary for different ownership.
User: A person who initially created a file or directory will become the owner of that. By default, you can call a user the owner.
Group: any group on the Linux system may contain several users with the same features and access to the file. It will save the time of the admin by assigning the different users with access individually. Then, they simply add the user to the group, and all access will automatically update all access for that user.
Other: This group of users do not belong to any particular group and do not create the file but can access the file. If you are setting any access permission for this group, it will be implemented to all the users by default.
Linux system has the permission parameter to distinguish between different types of ownership available. It helps prevent one file from being accessed by another user on the system, maintaining the system’s integrity. In addition, permission helps in defining user behavior.
Permissions in Linux
You can use three different types of permission in a Linux system that can be implemented for the ownership, as mentioned earlier.
Read: if you have the read permission, then you can easily open and read the file. However, in the case of a directory, you can only get the details of the directory.
Write: if you have to write permission for any file, you can edit that file. However, you will add, remove, and rename the files present in the directory in the case of a directory. Even if you have permission for the file but no the directory, you can only edit the file’s content but not rename, move, or delete the file name.
Execute: if you want to execute any file, its extension must be “.exe”, allowing you to run the file. If you do not have the execute permission, you may not run that file in the Linux environment. So, to set the system’s permission, the admin’s can help you with that.
Checking the File and Directory Access and Permission
You can check the permissions of the file via its mode bits. These bits help in identifying the actions you can carry out using a specific user account.
If you want to list all the files present in the current directory with detailed descriptions, including access and permission, run the below command.
The above sequence of rwx represents the read, write, and execute access for the user, group, and others. The leading “-” will indicate the type of the file. The “-” indicates the regular file. Here, rwx represents the following:
- r = read permission
- w = write permission
- x = execute permission
- – = no permission
There are various file types present in the Linux system, and the leading character will represent the below file types.
- – = represents Regular File
- d = represents Directory
- l = represents Symbolic Link
- b = represents Block Special Device
- c = represents Character Device
- s = represents Unix Socket (local domain socket)
- p = represents Named Pipe
In the below example, you can see the leading character is “d,” representing.
Explaining the Permission
Explaining the permission for the above example.
In the above example, the leading character represents the directory, followed by the permissions for the user (owner), group, and others.
Then, the first part, “rwx,” represents the access for the owner. It means that the owner can do actions like read, write, and execute on the directory.
Then, the second part, “r-x”, represents the access for the group. It means that the group can read and execute only on the current directory. But the other users present within the group will not write action to the directory.
Then, the last part, “r-x”, represents the access for the others. It means the remaining users will be able to implement read and execute actions on the directory. But the users will not be able to write to the directory.
Changing Permissions Using The “chmod” Command
If you want some files to be personal and not be shared with other users on the Linux system, you can achieve this by changing the permission to that particular file.
Linux provides you a “chmod” command to change the access and permission for a file or directory. Also, you can set the read, write, and execute access according to the user roles.
You can use the “chmod” command-line command with the help of the following syntax:
You can use the “chmod” command in two different ways- absolute mode and symbolic mode.
Using Absolute Mode
In this mode, the access and permissions are represented in the octal number. You can check the table as shown below for various access combinations.
|0 represents||No Permission||—|
|3 represents||Execute and write||-wx|
|5 represents||Read and execute||r-x|
|6 represents||Read and write||rw-|
|7 represents||Read, Write and Execute||rwx|
Now, we will discuss these octal representations with examples.
First, the file permission is shown below.
After we changed the access to (764) with “chmod” command is shown below.
The changed permission will specify that the owner is able to perform read, write, and execute actions now. User Group will be able to read and write. And the remaining users can only read.
Using Symbolic Mode
Unlike Absolute mode, Symbolic mode allows you to change the permission for a particular owner. You can use the mathematical operators for changing these permissions.
|+||It will add an access or permission to a file or directory|
|–||It will remove the access|
|=||It will set the access and overrides the permissions set earlier.|
You can use the below notations for specifying the ownership.
Here, we are considering a “sample” file that is having the below-mentioned permission.
Now we are setting the permission as shown below.
In the below example, we are about to add the execute permission to the user group.
In the below example, we are removing the “read’ permission from the user.
How to Change Ownership and Group?
Run the below-mentioned command-line command. Using the below command, you can change the ownership of a file or directory.
For changing the user along with the group for a particular file or directory, run the below-mentioned command-line command.
Run the “ls -l” command to check the ownership for a file or directory as shown below.
For changing the file owner for the above file to n100, you will require the sudo access.
The ownership has been changed, as shown below.
If you want to change the user and group to the root, run the below command.
You will get the output as below.
Linux is the most stable distribution among all operating system. You will get complete security over your files and directories. If you are a Linux admin or have sudo access, then you can play around Linux changing and setting access to various users and groups. These access will distinguish you from other roles and maintain privacy of someone’s data.
It is highly beneficial when you are working in a strict project and crucial data needs to be saved from unnecessary access.