In this tutorial, you will see how to create a new user in Linux from command line and GUI.
Add User From Command Line
To create a user in Linux you can either use adduser
or useradd
. The main difference between these two commands is that adduser
is more user-friendly, whereas the useradd
command is a low-level command for system services and scripts to use. We will show you how to use both.
Adding a user with adduser command
The syntax below can be used to add a new user with the adduser
command. Remember to put your own username in place of “username” in the example below.
$ sudo adduser username
Once executed, this line will show you a prompt window that will ask you to specify the user’s basic information that you can see in the image below:
Adding a user using useradd command
Example 1. The following syntax is used for the useradd
command. Replace “username” with that of your desired account name.
$ sudo useradd username
You will notice right away the difference from adduser
command. No prompt windows will be shown to configure the user’s password or home directory.
Example 2. To set the user’s password simply use the passwd
command.
$ sudo passwd username
Example 3. Adding a user while also generating their home directory with the -m
option.
$ sudo useradd username -m
Example 4. If you want to specify the user with a custom home directory you need to add the -d
option to the command above, followed by the path to the home directory.
$ sudo useradd username -m -d /home/accounts/username
Example 5. If you want to specify the user’s default shell, use the -s
command.
$ sudo useradd username -s /bin/sh
Adding a user through the GUI
The steps for creating a new user via GUI will vary depending on your desktop environment and Linux distro. The steps below will work for GNOME on Ubuntu.
Step 1. Go to the system settings in the right corner of the desktop screen. Then click on the users tab.
Step 2. Click on the unlock button and provide the authentication required then click on add user.
Step 3. Finally add the information you need for the new user and then click the add button.
Conclusion
Now you know how to add a user with adduser
and useradd
commands, as well as from GUI. You may also be interested in knowing how to add or remove a user from group.