User Management in Linux

User Management  in Linux

User Management

User management in Linux refers to the process of creating, modifying, and controlling user accounts on a Linux system. It involves tasks such as creating new user accounts, assigning user privileges, setting user passwords, managing user groups, and handling user access to files and directories. User management plays a vital role in maintaining system security, organizing access control, and ensuring proper resource allocation on a Linux system.

To add a user account

we have a user with the name Shantanu and we want to add Shantanu then we can do it by the following command:-

sudo useradd -m Shantanu

Now we can set the password by using the command:-

sudo password Shantanu

Now if we want to see where the user is added then we can check it by:-

sudo cat /etc/passwd

Suppose we have created three more users with the names Isha, Anuva, and Akhand. Now we have five users and among the five users Isha and Anuva are part of the group called A and Shantanu,ubuntu and Akhand are part of the group called B. In Linux, if we want to add a user to a group, then we have to create a group and here we have to create the two groups with the names A and B.

sudo groupadd A

sudo groupadd B

Now if we want to see whether the group is added or not then we have to do it by the following command:-

sudo cat /etc/group

Now if we want to add users to the group then we can do it by the command:-

sudo gpasswd -a Shantanu B

here we have added Shantanu to group B. But if we want to add multiple people into the group with a single command we can do it by the following command:-

sudo gpasswd -M ubuntu, Akhand B

here we have added Ubuntu and Akhand in group B. Now if we want to see what is inside the group then we can do it by the following command:-

sudo cat /etc/group

Now we can see that in the group B we have ubuntu and Akhand inside it like this format -> B : X : 1005 : ubuntu, Akhand We have added Shantanu to the group, so why are we seeing that only ubuntu and Akhand are part of Group B?

This is because add Shantanu we have used -a and to add ubuntu and Akhand we have used -M.

What is the difference between -a and -M?

-a is used to add one user to the group and -M is used to give a member list to the group. When we give a member list then the already existing user is overridden. So whenever we use -M then the user which is already present we need to add that too. so we have to do:-

sudo gpasswd -M Akhand,ubuntu,Shantanu B

Now we can see all three in group B. We also have to add Anuva and Isha to group A then we can do it by:-

sudo gpasswd -M Anuva, Isha A

This is the demonstration of User management in Linux.