Introduction to Linux Add User
In the Linux operating system, the adduser command is used to create or add the user to the Linux server. There are different ways to add users to the Linux environment, like useradd, adduser. The Linux ecosystem is supporting the multi-user. It is more important to track and control user and group levels properly.
Note: The adduser command is similar to the useradd command only. Because it is a symbolic link between it, both the command have similar behavior.
Syntax of Adduser command
useradd [options ] LOGIN
useradd -D [options]
- useradd: We can use the “useradd” keyword in the syntax or command. It will take different arguments likeOPTION, LOGIN type, user name, etc. As per the provided arguments, it will create the new user with the required configuration.
- OPTION: We can provide the different flags as options that are compatible with the “useradd” command.
- LOGIN: We can provide the different LOGIN type to the “useradd” command. Accordingly, It will provide shell access.
Note: The useradd and adduser command is nothing but a similar command.
How does Linux Adduser Command work?
The Linux environment is supporting the multi-user session handler. Due to which the number of users can access the different data. Hence it is mandatory to keep the proper user in the necessary group with proper access and user-config.
When we are creating any new user on the Linux environment. The below process will happen every time.
1. The controller will edit the below files for the new user account.
2. It will create the new home directory for the new user (default path is /home/$new_username)
3. It will automatically setup the necessary ownership and the permissions on the home directory.
We will get the entire user’s detailed information in the “/etc/passwd” file. As per the Linux system administrator, it is important to understand the points below.
- Username: The user name is “test_user”. The same user name is used in the system login. The login username should be between 1 to 32 characters long.
- Password: The password is displaying the “x”. But the actual password was saved in the /etc/shadow file in an encrypted format.
- User ID (UID): The user id is 1004. The user having their user id. It is very important for user identification on the system level. The UID or user-id “0” is default reserved for the root user.
- Group ID (GID): The group id is “1004”. The primary Group ID i.e. the GID. The GID information is store in the “/etc/group” file.
- User Info: Currently the user information is blank. as per the requirement, we can add the user info for further reference.
- Home Directory: The home directory path is “/home/test_user”. But as per the requirement, we can change the home directory path.
- Shell: The shell has provided to the user is “/bin/bash”. As per the requirement, we can provide different shell access.
Examples to implement Linux Add User command
Here are the following examples mention below:
Example #1 – Create New User
The “adduser” command is a very simple and common way to add or create a new user in a Linux environment.
As per the above command, we are adding the “demo_user” with the help of the adduser command.
Screenshot 1 (a)
Screenshot 1 (b)
Example #2 – Specific User ID
By default, when we are creating a new user. The system will provide the user ID and is in the sequential manager. But as per our requirement, we can also provide the specific user ID.
adduser -u 2000 demo_user1
As per the above command, we are adding the specific user ID for the “demo_user1” user. We are using the “-u” option to add the specific user id i.e. 2000.
Screenshot 2 (a)
Screenshot 2 (b)
Example #3 – Specific Group ID
In the adduser command, we can set our user ID. Similarly, we can also change the group ID as well.
useradd -u 2001 -g 10000 demo_user2
As per the above command, we are adding the specific group ID for the “demo_user5” user. We are using the “-g” option to add the specific group id i.e. 1000.
Example #4 – To Add the New User in Multiple Groups
In the Linux environment, we are having the functionality to add the new user in multiple exiting groups in a single shot.
useradd -G data_user,demo_user demo_user6
As per the above command, we are using the “-G” option in the useradd command. We are adding the “demo_user6” user to the “data_user,demo_user” group.
Screenshot 4 (a)
Screenshot 4 (b)
Example #5 – Add User without Home Directory
In the adduser command, we can add the new user without a home directory. The new user will store their data on the “root” location if they are having the proper permission and access.
adduser -M demo_user8
By default, the home directory will add to the newly created user. But in adduser command, we are having the facility to add the user without “home directory”. We have added the “demo_user8” without a home directory.
Example #6 – Add User with Account Expiry Date
In the adduser command, we can set the user account expiry date of the user.
useradd -e 2060-01-01 demo_user9
chage -l demo_user9
We have set the account to expire date“Jan 1, 2060” for the user “demo_user9” user. After the expiration date, the account will stop performing.
Conclusion – Linux Add User
We have seen the uncut concept of “Linux Adduser Command” with the proper example, explanation, and command with different outputs. The adduser command is used to add the new user to the Linux environment. We can add the user with proper configuration and user limitations.
This is a guide to Linux Add User. Here we have discussed how Linux Adduser Command works along with the commands and respective examples. You may also have a look at the following articles to learn more –