2 Ways to Create User Account in Ubuntu Using Terminal

Ubuntu is one of the most used distributions among all Linux-based operating systems. It is a multi-user system. Moreover, the terminal or the command line interface (CLI) is one of the most powerful tools for managing administrative tasks of this system. Therefore, it is a must for the users to know how to create user account in Ubuntu using the terminal. In this article, I will provide 2 ways to create a user account in Ubuntu using a terminal.

Key Takeaways

  • Two different ways to create a new user using the terminal.
  • Getting familiar with sudo, adduser, useradd, passwd, getent, grep and a few other commands in Linux.
  • The process of setting a new password for the newly created user.

Requirements

  • Need to be a root user or have root/sudo privileges to add, remove or modify a user in Ubuntu.
  • The USER_NAME must begin with a lowercase alphabetic character and not contain any spaces or ‘@’. Furthermore, it can only include some valid letters, numbers and symbols like ‘’, ’_’, ‘.’ etc.

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSProcess flow chart of creating user acount in Ubuntu using terminal.

Watch 2 Methods to Create a User Account in Ubuntu Using the Terminal

2 Methods to Create a User Account in Ubuntu Using the Terminal

You can easily create a new user in Ubuntu from the terminal using two different commands i.e. the adduser & the useradd commands. In this article, I will show you two approaches using these two commands.

You can read our Comparative Analysis of Methods to distinguish between these two methods and best pick one for your need.

Method 01: Using the “adduser” Command to Create User Account in Ubuntu

You can easily create a new user account in Ubuntu using the adduser command. This command prompts all the required information such as user password, home directory & group by default.

Now, I will create a new user named “harry” using the terminal. The following guide will help you.

Command Syntax >

sudo adduser USER_NAME

Steps to Follow >

➊ At first, press CTRL+ALT+T to open the Ubuntu Terminal.

➋ After that, copy the following command:

sudo adduser harry
Explanation
  • sudo: Grants administrative privileges.
  • adduser: Adds a new user.
  • harry: Name of the user account.

➌ Then, press the ENTER button.

➍ Finally, input the password of the currently logged-in user.Adding a new user to the system with the adduser command in Ubuntu.

Output Analysis

After entering the password, the command creates a new user account named “harry”. In addition to that, it will then create a new group with the same name as the user and assigns it to the “harry” group.

Next, the command creates a home directory for the new user at “/home/harry”. Moreover, this directory will be used to store the user’s personal files and settings.

Finally, the command copies the contents of the “/etc/skel” directory to the new user’s home directory. The “/etc/skel” directory contains a set of default files and directories that are copied to new user accounts, providing a basic set of files and settings for the user.

➎ Now, set a password for the newly created user and set other required information.

However, you can skip setting other information by pressing ENTER each time.

Try to set a unique and strong password. Otherwise, you will get a warning message such as “BAD PASSWORD” as in the following image.

➏ Finally, press Y to confirm your given information.Setting a password, Filling up the required information of the new user and finally confirming to create the new user. After confirming all the given information by pressing Y, the new user will be created.



Method 02: Creating User Account by Using the “useradd” Command in Ubuntu

Though the useradd command is not interactive like the adduser command, you can quickly create a new user account with the useradd command using the following steps.

Command Syntax >

sudo useradd USER_NAME

Now, I will create a new user named “tom” from the terminal using the above-mentioned useradd command and syntax. To do the same you can follow the below instructions.

Steps to Follow >

➊ First, open the Ubuntu Terminal.

➋ Then, type the following command:

sudo useradd tom
Explanation
  • sudo: Grants administrative privileges.
  • useradd: Adds a new user.
  • tom: Name of the user account.

➌ After that, press the ENTER button.

➍ Finally, input the password of the currently logged-in user.Adding a new user account with the useradd command in Ubuntu using terminal.In the above image, you can see that after providing the current user password, I have been able to create the desired user.

➎ Now, to access the newly created user “tom”, set a password for the user by executing the following command:

sudo passwd tom
Explanation
  • sudo: Grants administrative privileges.
  • passwd: Sets/Changes password.
  • tom: Name of the user to be created.

Setting a password for the new user "tom" by using the passwd command. In the above image, you can see that I have successfully set a password for the newly created user.

Comparative Analysis of Methods

After going through the above two methods you might get confused about which one to choose between the two. However, don’t worry I’ll make it easier for you with the following full-on comparison between the methods of creating users in Ubuntu using the Terminal.

Methods Pros Cons
Method 1
  • It prompts all the required information to be filled in.
  • Sets the user’s password, home directory & group by default.
  • It is not readily available on all Linux distributions or on all versions (i.e.Alpine Linux, Arch Linux).
  • Limited number of options to customize the command which may be a concern for advanced users.
Method 2
  • Users can modify the command to their needs with a large number of available options.
  • It can be easily integrated scripts to automate user creation and make multiple user creation possible.
  • Needs to use a specific syntax format and some specific options to work with this command.
  • It doesn’t come with the preconfigured settings.

In summary, both methods have their own pros and cons. Furthermore, the choice between the two depends on the user’s skills, the particular requirements of the user to be created and the intention of the administrator.

Complementary Information

Besides, knowing about creating new users through the Ubuntu terminal, you will find the below information helpful.

Check If Newly Created User Exists in Ubuntu

To check whether your desired new user account has been created, use the following command syntax.

Command Syntax >

getent passwd | grep USER_NAME

Now in this section, I will check whether the newly created user named “tom” exist on my system. You can do so by following the given steps.

Steps to Follow >

➊ At first, open the Ubuntu terminal.

➋ Then, type the following command into the command prompt.

getent passwd | grep tom
Explanation
  • getent: Looks into the administrative database that is given as its argument.
  • passwd: Contains user information.
  • Pipe (|): Redirects the standard output.
  • grep: Looks for a specific pattern given to it as an argument.
  • tom: Username of the newly created user.

➌ Finally, press ENTER.Checking whether the new user "tom" exists in the system.In the above image, you can see that the newly created user account “tom” actually exists on the system.

Output Analysis

In the above image, each field in the output represents:

  • tom: Name of the user account.
  • x: Password field in a non-readable format ‘x’. which means that the password is stored in the /etc/shadow file.
  • 1002: The user ID (UID) for this user.
  • 1002: The group ID (GID) for this user.
  • ,,,: Comment field. These three consecutive commas mean that for this user it is empty.
  • /home/tom: Home directory of this user.
  • /bin/sh: Default log-in shell of this user.



Delete User and Home Directory in Ubuntu

You can easily remove any user from the system using the terminal with the userdel command in Ubuntu. Here, I will delete the user account named “tom”. To do the same follow the below procedures.

Steps to Follow >

➊ At first, open the Ubuntu terminal.

➋ Then, type the following command into the command prompt.

sudo userdel tom
Explanation
  • sudo: Grants administrative privileges.
  • userdel: Deletes a user account.
  • tom: Username of the user to be deleted.

➌ After that press ENTER.

➍ Finally, provide the password of the currently logged-in user.Removing the user named "tom" by using the userdel command in Ubuntu using terminal.In the above image, you can see that I removed the user “tom” using the Ubuntu terminal. However, in this method, the home directory will still exist after deleting the user. Moreover, you can check whether the home directory is still on the machine or not by running the following command:

ls /home

After pressing the ENTER button, you will see the home directory of the deleted user like the image given below.The home directory of the recently deleted user "tom" still exists.To delete the user along with its home directory, you can type the command below.

sudo userdel -r tom
Explanation
  • sudo: Grants administrative privileges.
  • userdel: Deletes a user account.
  • -r: Removes home directory and its contents.
  • tom: Username of the user account.

After pressing the ENTER button, you will need to provide the password of the currently logged-in user.The user "tom" is deleted along with its home directory by using the -r option with the userdel command.In the above image, you can see that the home directory is deleted along with the user.

Give Root Privileges to an Existing User in Ubuntu

If you’re a root user or you’ve root privileges in Ubuntu, you can give root privileges to another existing user by adding it to the sudo group. For this, you have to use the usermod command in Linux. To do so follow the given instructions.

Steps to Follow >

➊ First, open the Ubuntu terminal.

➋ Next, type the following command into the command prompt.

sudo usermod -aG sudo tom
Explanation
  • sudo: Grants administrative privileges.
  • usermod: Modifies an existing user account.
  • -aG: Adds a user to the specific group.
  • tom: Username of the user account.

➌ Then, press ENTER.

➍ After that, provide the password of the currently logged-in user.

➎ To check whether the user is added to the sudo group run the following command.

groups tom

➏ Finally, press ENTER again.The user "tom" has been given root privileges by using the -aG option with the usermod command.In the above image, you can see that I have given the user “tom” root privileges by adding it to the sudo group. Furthermore, I checked its group by using the groups command and tested its elevated powers by using the ls command.

Conclusion

Creating a new user account using the terminal is pretty simple and time efficient compared to that of using the graphical user interface (GUI). By following this article, you will be now able to easily add new users to your Ubuntu system. In simple words, you just need to follow the series of some simple commands and provide the necessary information and set up a strong password and you’re good to go.

People Also Ask

What command is used to create a user?


In Linux-based systems, you can create new user accounts with two different commands i.e. adduser & useradd command. Both commands have similar options and outcomes, however, the adduser command is more interactive.

Can I create multiple users in Linux at once?


No, you cannot create multiple users at a time in Linux directly using adduser or useradd command. Because they do not support multiple usernames at once. However, you can use a bash script containing loops to do that.

How do I get the list of users in the command prompt?


You can check the /etc/passwd files from the command prompt to view the users. Furthermore, you can run the following command “cut -d: -f1 /etc/passwd” in the command prompt to get the list of users.

What are the 3 user account types in Linux?


The three user account types in Linux are as follows, 1) the root user, 2) the regular user and 3) the service/system user.

What is the admin account?


In Ubuntu, any user belonging to the sudo group is considered as the admin account as it can perform all kinds of administrative tasks in the system.

What is a local admin account?


In Ubuntu, the local admin account is the user that performs administrative operations on the local system. By default, the first user created during the Ubuntu installation is considered as the local admin account.

What is a regular user of Linux?


In Linux-based systems, users without root privileges are considered as normal/regular users. Regular users can only perform non-administrative tasks like managing files, running programs and using networks etc.

What is a service user of Linux?


In Linux-based systems, service users are created to manage some specific system services or daemons which run in the background.

Can I create two users with the same name in Linux?


Yes, it is possible to create two users with the same username by specifying two different UIDs for them. However, remember that you should not use the same username because it will create confusion and difficulty in permission management.

Can two users have the same UID in Linux?


Yes, you can assign two or more users to the same user ID (UID). However, you should be careful while doing that because users with the same UID will share everything.

How to delete a user in Ubuntu?


If you are a root user or have root privileges, you can delete a user from the settings>users or you can do it using the userdel command from the terminal.

Relaed Articles

5/5 - (4 votes)
Md. Ashakul Islam Sowad

Md. Ashakul Islam Sowad

Hi, I am Md. Ashakul Islam Sowad from Dhaka, Bangladesh. I have completed my undergraduate degree in Biomedical Engineering from the Bangladesh University of Engineering and Technology (BUET). I love to watch football and play video games in my free time. Here, I am working as a Linux Content Developer Executive. Furthermore, as a Linux enthusiast, I am always learning new things about Linux-based systems and I’ll be sharing them here. Read Full Bio

We will be happy to hear your thoughts

Leave a reply

LinuxSimply
Logo