Create User Account in Ubuntu Using Terminal [2 Methods]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

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 a 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.

Process flow chart to create a user account in Ubuntu using the terminal:Process flow chart of creating user acount in Ubuntu using terminal.[Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS]

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 pick one for your needs.

1. Create User Account by the “adduser” Command 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.

To create a new user account, let’s say “harry”, follow the steps given below:

  1. At first, press CTRL+ALT+T to open the Ubuntu Terminal.
  2. 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.
  3. Then, press the ENTER button.
  4. Finally, input the password of the currently logged-in user.Adding a new user to the system with the adduser command in Ubuntu.
    EXPLANATION

    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.

  5. 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.
    Warning: Try to set a unique and strong password. Otherwise, you will get a warning message such as “BAD PASSWORD” as in the following image.
  6. 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.


2. Create a User Account Using the “useradd” Command

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

To create a new user named “tom” from the terminal using the useradd command, follow the below instructions:

  1. First, open the Ubuntu Terminal.
  2. Then, type the following command:
    sudo useradd tom
  3. After that, press the ENTER button.
  4. 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.
  5. Now, to access the newly created user “tom”, set a password for the user by executing the following command:

    sudo passwd tom

    Here the passwd command sets/changes the password.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 to Create a User Account in Ubuntu

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.

Check If a Newly Created User Exists in Ubuntu

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

  1. At first, open the terminal.
  2. Then, type the following command:
    getent passwd | grep tom
    EXPLANATION
    • getent: Looks into the administrative database that is given as its argument.
    • Pipe (|): Redirects the standard output.
    • grep: Looks for a specific pattern given to it as an argument.
  3. 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:

  1. At first, open the terminal.
  2. Then, type the following command into the command prompt.
    sudo userdel tom

    Here the userdel command deletes a user account.

  3. After that press ENTER.
  4. 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 ls /home command.
    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.

  5. To delete the user along with its home directory, you can type the command below.
    sudo userdel -r tom

    Here the option -r removes the home directory and its contents.

  6. 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

Root privileges in Ubuntu provide unrestricted access to system commands and files. The root user, or superuser, can perform critical tasks like installing software and modifying system configurations.

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. Check the given instructions to do it:

  1. First, open the Ubuntu terminal.
  2. Next, type the following command into the command prompt:
    sudo usermod -aG sudo tom
    EXPLANATION
    • usermod: Modifies an existing user account.
    • -aG: Adds a user to the specific group.
  3. Then, press ENTER.
  4. After that, provide the password of the currently logged-in user.
  5. To check whether the user is added to the sudo group run the groups tom command.
  6. 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

Can I create multiple users in Linux at once?

Yes, you can create multiple users at a time in Linux directly using a simple bash script. Here’s an example:

#!/bin/bash

for username in user1 user2 user3
do
useradd $username
echo "Password1234" | passwd --stdin $username
done

Replace the usernames and passwords as you need.

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 cut -d: -f1 /etc/passwdcommand to get the list of users.

What is the admin account?

The admin account is a privileged user account that typically has elevated permissions and control over a computer system, network, or application. It is often used for system administration tasks, allowing the user to configure settings, install software, and manage other user accounts.

What is a local admin account?

A local admin account in Ubuntu is a user with elevated privileges for system-level tasks, like software installation and configuration changes. It enables users to manage the system effectively, performing crucial administrative functions. 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?

A service user in Linux refers to a system account specifically created to run a service or application. It is designed to enhance security and manage permissions by allowing the service to operate with minimal privileges. Service users help isolate and safeguard the system, preventing potential security vulnerabilities.

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

No, in Linux, you cannot create two users with the same name. Usernames must be unique to avoid conflicts and ensure proper user identification and management.

Can two users have the same UID in Linux?

No, two users cannot have the same UID (User ID) in Linux. Each UID must be unique within the system, as it is a fundamental attribute used by the operating system to identify and manage user accounts. Having duplicate UIDs can lead to confusion and access control issues.

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 sudo userdel <username> command from the terminal.

Relaed Articles

4.8/5 - (6 votes)
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

Leave a Comment