Table of Contents
Linux useradd Command with Examples
The useradd is a low-level utility used to manage users on the Linux system. By using
useradd utility you create new users and assign them to the groups. As Linux is a multiuser system it’s important for the administrator to manage tasks like adding user, removing user, assigning a user to the group, etc. In this tutorial, we are going to learn Linux useradd command with examples.
Basic Syntax of
When creating a new user with given options using useradd command, It reads
/etc/default/useradd file for default values and
/etc/login.defs file for password policies, user id ranges etc.
Following is the basic syntax for
useradd command in Linux.
useradd [OPTIONS] USERNAME
OPTIONS: These are the options used with useradd command specified here.
USERNAME: Name of the user that will be used with this command.
How to Create a New User in Linux System
To only create a new user using
useradd command you run this command without any options.
Run the following command to create a user names
demouser in your Linux system.
After completing the execution of the above command, it will create the new user using default values specified in
Now to make this user login to the system you should set the password to the newly created user. To set the password to
demouser you can run below command:
Now you will be asked to enter the password, enter the password and confirm it when you asked.
How to Create User with Specific User ID
When we create a user using useradd function user ID will be assigned to the user reading
/etc/login.defs files. You can also create a new user with specific user id by using
-u option with
To create a user with User ID 1401 you can run following command in the terminal:
useradd -u 1401 demouser1
Confirm and verify User ID with
id -u demouser1
The output should be:
How to Create a User With Home Directory
To create a user with home directory you should use
-m option with
Create a user named
demouser2 with home directory run below command:
useradd -m demouser2
Here the new user will be created with home directory
To confirm the creation of the directory run below command:
ls -a /home/demouser2
In this tutorial, you have learned Linux useradd Command with Examples successfully. If you have any of the queries regarding this then you can comment below.