As we are all aware that Linux is a multi user operating system. So, there can be a case where the System Administrator has to add different users & set permissions for each of them Today, in this blog we are going to look how we can add users and groups and set file permission for each of them.
How can we add users in Linux Machine ?
Mainly there are two utilizes to add a user in Linux Machine which are “useradd” and "adduser". The “useradd” is a low-level utility command which is more time consuming for beginners so, today we are going to look at “adduser” because it is more kind of symbolic link and makes easier for the beginners to get started.
To add a user we need to type :
- sudo adduser username
We need to specify sudo before the adduser command because the normal user or the user with the low priviliges doesn't have any access to add a user in their machine. After the adduser command we need to specify the username.
For ex: If we want to add username as “Robot” then we have to type:
- sudo adduser Robot
This command will automatically create a default directory and default shell for the user robot. After the command is successfully entered we can verify either the user Robot is added or not by going through etc/passwd . It is a text file where all the users details is being hold.
To change a Password of the user:There can be a certain situation where the user doesn't remember his password. In those case the user can re-change it password by typing the command:
- sudo passwd username
After the username is specified the terminal will ask new password for the user to enter. After the new password is entered the user can login through newly changed password.
To delete the user:
Deleting a user from the Linux Machine is quite easy. To delete a user from our System simply we have to type:
- sudo userdel username
After the command is entered, now the user has no longer access in our machine.
How can we add groups in Linux Machine?
Adding a users and setting the file permission for the different layers of users particularly can be more time consuming and more frustrating jobs for the System Administrator so to solve this problem adding groups come into play. By default while adding a user name as robot in Linux it will also create a default group with the same name as “robot”.
The main approach of adding a group by system administration is to manage the users and set file permission in the few time and in a more convenient way.
To add a group we need to type:
- sudo groupadd groupname
After the groupadd command we need to specify the groupname . The group name can be anything of your choice but for this example; If I want to add group called developers then we need to type:
- sudo groupadd developers
After the command is successfully entered we can verify either the group is added or not by visiting through /etc/group . It is a text file where all group details is being hold.
To delete the group:
Deleting a group from linux is simple and easy as compare to other commands. So to delete the group we need to type:
- sudo groupdel groupname
After this command there will be no any groupname as specified by the user.
How can we add and delete specific user and from Linux?
Suppose, the system administration has created a group called developers and now he want to add the users who comes under those category to keep the file and permissions separate from other groups & users. It is one of the main advantage of Linux where the users can be added to a specified group in a quick time and in a more easier manner. Let’s look how we can do it with a command:
To add a specific user in a group called developers we need to type:
- sudo adduser username developers
suppose if we want to add user called robot in this group. We can do it through:
- sudo adduser robot developers
To delete a specific user called “robot” from a group called developers:
- sudo deluser robot developers
File Permissions In Linux:
As we have already seen the fact that , Linux is a multi user operating system and how we can manage different users on it but besides the scene, Have you ever noticed how the files and directories created by a specific user can't be altered by any others playing on the same system?
So, Here the File Permissions comes into play.
What is File Permissions?
As, Linux has many builtin features but the most renowned features is it's Permission based security feature where the system administration or the owner of the file or directory can set permission level to different types users and groups in the system.
Mainly there are three types of Permissions on the Linux System:
- Read:The read permission gives the authority to the users or groups to read the contents of a file. It is denoted by "r" in Linux system.
- Write: The write permission gives the authority to the users or the groups to change the content of a file. It is denoted by "w" in Linux system.
- Execute: The execute permission gives the authority to the users or the groups to execute the file. It is denoted by "x" in Linux system.
As, we have looked the types of permission. Now, let's understand the types of ownership for a file or the directory.So, whenever the files or the folders is being created in Linux system by default it is being created based on the three user based permission groups i.e. each files or the directory has 3 types of ownership which are enlisted below:
- Owner/User : The owner permission will be applied to the owner of a file. By default, the user who has created the file will be the owner of a file. It is denoted by "u".
- Group: The group can contain multiple users on it. Suppose the certain files or folders is being assigned to the group then the users belonging to that group can have only the permission to access that files or the folders. It is denoted by "g".
- Others: The others users permission in Linux means the permission given to all users except from the owner and groups who don't comes under those category. It is denoted by "o".
Now, let's see how we can set the file permissions for files or the folders,Mainly there are two ways to set permissions in unix/Linux System. Those are binary & symbolic representation:
Let's have a look at setting the permissions through binary representation. In binary representation there are 3 three numeric terms which we have to remember while setting the permission which are given below:
4 - It means to give a read permission.
2 - It means to give Write Permission
1 - It means to give execute permission
Now, let's see the example. Suppose we have two users in our system that are "robot" & "hulk". Now, robot has created the file that means he is the owner of the file and by default "robot" group will be created same as owner name. Now, he want's the other user named as "hulk" to give read permission only. So, the task can be achieve through the command as:
- chmod 774 fillename
In the above command the chmod stands for change mode and the first two 7 numeric terms defines that, we have set all read write and execute permission for the user "robot" & group "robot" and the last 4 digit describes that we have set read only permission for the user "hulk".
Symbolic Representation:
The same task which we have accomplished above can de done through the symbolic way also.
r = It means we have read permission.
w = It means we have write permission.
x = It means we have execute permission.
Now, let's see the sample example as we discussed above but now add the execute permission for the user "hulk". To do we need to type the command as:
- chmod o+x filename
These command simply means that we have given execute permission for the other users where "o" denotes the "other users" and "x" denotes "execute permission".
Thankyou,
Author - Saroj Khadka
Comments
Post a Comment