As a systems administrator or regular Linux user, you may be required to create additional users in the system so that other users can reap the benefits of interacting with the system. In this tutorial, we will walk you through how to create and manage new users on a Linux system.
Table of Contents
Creating New Users
There are 2 commands that can be used to create users in the system.
Let’s have a look at each of them in detail.
adduser command is a user-friendly Perl script that creates a fully functional Linux user on the system.
The syntax for adding a new user to a Linux system is as shown below
Copy# adduser username
adduser command offers a high-level interface and performs the following functions
- Creates a new user called ‘username’
- Creates a new group with the new user’s username
- Places the new user in the newly created group bearing user’s username
- Creates a home directory (/home/username) and later copy the files from
- Prompts for additional information about the new user such as Full Name , Room Number, Work Phone, and Home Phone
Adding a new user
In this example, we are going to add a user ‘penguin’ to the system
Copy# adduser penguin
The list of users in a Linux system is stored in
/etc/passwd file. Therefore, to verify that the user has been created run
useradd command is a native binary command and is considered a low-level utility for adding users to the system. The command cannot achieve most of the functionalities that
adduser accomplishes at once and therefore , requires more options in its syntax.
The syntax for using the
useradd command is
Copyuseradd -option username
useradd command does not create a home directory for the new user like
adduser command. This is show in the output below where a new user ‘james’ has been created.
To create a user along with the home directory, use the
-m option as shown.
Copy$ useradd -m username
For example, to create user ‘james’ alongside his home directory, execute:
Copy$ useradd -m james
Now you can verify the existence of the home directory for the user ‘james’ by running:
Copy$ ls /home
-u (–uid) option
-u option creates the user with a specific UID (User ID). A User ID is a positive integer that is automatically assigned to a new user by the Linux system.
For example, to create a user ‘james’ with a UID of 1400 execute:
Copy$ useradd -u 1400 james
This can be verified by the command
Copy$ id james
Alternatively, you can verify the UID by running
Copyid -u james
-g (–gid) option
--gid option creates a user belonging to a certain group by specifying either the group name or the GID number.
For example, to create the user ‘james’ belonging to a new group called users, execute the command
Copy$ useradd -g users james
To verify this, run the command below
Copy$ id -gn james
-c (–comment) option
The -c (–comment) option allows you to create a user with a brief description of the new user. For example, to create a new user ‘james’ with a string “IT department” execute
Copy$ useradd -c "IT departmemt" james
The comment is stored in the
/etc/passwd file. You can use the
cat command to reveal the details of the user a shown
-e (–expiredate) option
If you want to define a date upon which a new user account will expire, then use the
For instance, to create a new user called ‘james’ with an expiry date set to
June 10 2019 execute
Copy$ useradd -e 2019-06-10 username
Next, use the
chage command to verify the user account expiry date:
Copysudo chage -l username
Adding users to sudoers group
Sometimes, you may need to delegate some administrative rights to regular users so that they can perform some administrative tasks. To accomplish this, you need to add them to the
One way of adding users to the sudoers group is by running the command below
Copy$ usermod -a -G sudo username
username is the user that you want to add to the sudoers group. For instance, to add the user ‘james’ to
sudoers group run the command
Copy$ usermod -a -G sudo james
To verify that the user ‘james’ has been added to the sudo group run
Alternatively, you can edit your
sudoers file using the
visudo command by running
This will open the file as shown below
Next, append the following line
Copyusername ALL = (ALL)ALL
Save and exit the text editor.
Now you can switch to the regular user and execute an admin command by preceding the username with
sudo as shown.
To completely delete a user from the Linux system, use the
userdel command with
-r attribute as shown
Copy$ userdel -r username
To delete user ‘james’ run the below command.
Copy$ userdel -r james
In this article, you learned how to create and manage new users in Linux with
useradd commands. These commands run across all distributions, both Debian and Redhat distributions.