Linux User Management: Step-by-Step Instructions
What is User Management
User Management means say we have a system, which has to be used by various people i.e. the system is used by the developer's for developing, DevOps engineer's for creating cloud services, database engineer's for creation database. So, to manage all the users with different requirement toward a system is called User Management.
Let's see how user management is done:
- Create a Ubuntu EC2 machine in AWS and login into it.
[ 1.1 ] Creating, Adding, Deleting a user:
All the users who are currently using the machine are stored in /etc/passwd directory.
1.1) Lets see which is the current user with command, "whoami". So, the current user is "ubuntu".
i-x (EC2)
--------------------------
ubuntu@ip———:~$ whoami
ubuntu
1.2) Now lets create another user say mihir using command : sudo useradd user-name flag
i-x (EC2)
--------------------------
ubuntu@ip———:~$
sudo useradd mihir -m
1.3) After running the above command the user is created and added, but how to check if the user is added or not. The user is added in directory /etc/passwd. i.e. in /etc/passwd directory all the users connected to the system are present. So, cat the file.
i-x (EC2)
--------------------------
ubuntu@ip———:~$ sudo cat /etc/passwd
.
.
mihir:x:1001:1001::/home/mihir:/bin/sh
1.4) So, let’s set the password for the user using command: sudo passwd username
i-x (EC2)
--------------------------
ubuntu@ip————:~$ sudo passwd mihir
New password:
Retype new password:
passwd: password updated successfully
1.5) So, we have two user's 1. ubuntu which was the first user, 2. mihir which we created. So, currently ubuntu user is present. Lets check using "pwd", so we are having the "ubuntu" user currently.
Now lets try to move in the other user's directory i.e. mihir's directory using "cd /home/mihir". It will not allow why because the "ubuntu" user cannot go into "mihir" user's directory i.e. one user cannot go into another user's directory as there will be files and data of each user. And linux doesn't allow one user to go into another user's directory for safety reason.
i-x (EC2)
--------------------------
ubuntu@ip———-:~$ pwd
/home/ubuntu
ubuntu@ip———-:~$ cd /home/mihir
-bash: cd: /home/mihir: Permission denied
1.6) So, lets see how we can switch to another user i.e. "mihir" from the default current i.e. "ubuntu". We will use command switch user i.e. su username and create some files in it. So, we are entering into a new user "mihir" which is created from the default user "ubuntu". The default user "ubuntu" is created when we create the EC2 machine. So, when we login the machine then we enter as default user "ubuntu" and from default user we enter into a new user created. Once we switch to the new user "mihir" & to come out of it, to the default user "ubuntu" we use command "exit".
i-x (EC2)
--------------------------
ubuntu@ip———-:~$ su mihir
Password:
$ pwd
/home/ubuntu
$ cd /home/mihir
$ pwd
/home/mihir
$ touch file.txt
$ ls
file.txt
$ exit
ubuntu@ip————:~$ pwd
/home/ubuntu
1.7) So, let's delete the user using command : sudo userdel user-name and verify using "sudo cat /etc/passwd" command. So, see user "mihir" is deleted & only default user "ubuntu" is only there.
i-X (EC2)
--------------------------
ubuntu@ip————:~$ sudo userdel mihir
ubuntu@ip————:~$ sudo cat /etc/passwd ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash lxd:x:999:100::/var/snap/lxd/common/lxd:/bin/false
Conclusion
User management is important part of any field which exists in the world. So, for the Cloud and DevOps as well, and Linux being important part of the of most of the application in the world, it’s important to understand how to create, add, delete the user.
“““ Hope you had a great time going through the User Management i.e. how to create, add and delete the user in Linux OS, which will help you to manage the user’s in Linux OS. Please like, share and comment if you liked it and connect with me for more information…..”””
Subscribe to my newsletter
Read articles from Mihir Suratwala directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mihir Suratwala
Mihir Suratwala
Hi, How are you !! Hope you doing good.... I got introduced to Cloud initially. As I went ahead learning what is cloud and how it works, then got to know a field which is DevOps that makes Cloud model more effective. So, as I started working & got good experience on AWS. I have been learning the DevOps tool and technologies on how to use it with the Cloud, which will give me good understanding on how Cloud and DevOps go hand in hand to deploy my applications.