adduser command in Linux with Examples
This is #90DaysofDevops challenge under the guidance of Shubham Londhe sir.
Linux is a multi-user system, which means that more than one person can interact with the same system at the same time.
As a system administrator or root user, you have the responsibility to manage the system’s users and groups by creating and removing users and assigning them to different groups.
In this blog, let's understand how to do this operation in the Linux Environment:
If you are working on Debian/Ubuntu, first we need to install addusercommand using the below:
$sudo apt-get install adduser
In case Redhat/CentOS: $sudo yum install adduser
What is sudo here - (Super User Do) Basically when we are using the sudo command with a prefix it means we are granting temporarily a user administrative right. Use it wisely.
useradd - This is the command to add a user in Linux.
In the above example, useradd Rahul - It means I'm informing shell to add the user name Rahul, but in this example, there won't be a directory created with the name Rahul. Refer to the below example.
How to create a user with a home directory in Linux:
-m - This is the option that we need to use. Refer to the below example.
If we want the user to have a home directory in a different place than the default, use the useradd -d option.
If you want to switch user from current to newly created user, you can do it by using the below command:
$su - switch user
In the above screenshot, there are two users ayyapa, raghu. Using su raghu I switched the user to raghu. In order to come out of the terminal we can type exit or ctrl+d.
Let's say I want to change the username from raghu to devops, we can do it using the command:
$usermod -l new_user_name old_user_name
In order to see all the users created we can check in the /etc/passwd directory/file.
End of the file, usernames will be listed.
Please, feel free to drop any questions in the comments below. I would be happy to answer them.
If this post was helpful, please follow and share it with others.
Thank you for reading💚
Rahul Naik 🌻✨