totn Linux

Linux: How to Create a User in Ubuntu Linux Server 16.04 LTS

In this Linux system administration tutorial you will learn how to create a user on an Ubuntu Linux Server 16.04 LTS (Xenial Xerus) system with screenshots and instructions.

Description

System administrators create user accounts to allow access to the system or system services. To add a new user, you will use the useradd command.

Syntax

The syntax for the useradd command is:

useradd -u User_ID -g Group [-d Directory_Path] [-m] [-c "Full_User_Name"] User_Name

Prerequisites

The useradd command requires the following parameters:

-u User_ID
The -u parameter indicates that a user number will follow. This is the user number that will be assigned to this new user. The user number must be unique.
-g Group
The -g parameter indicates that a group number will follow. This can be either a group ID or group name that the user should be assigned to.
-d Directory_Path
Optional. The -d parameter sets the location of the user's home directory as specified by Directory_Path. Setting the home directory does not guarantee that the directory exists (see the -m parameter).
-m
Optional. The -m parameter creates the user's home directory if it does not already exist.
-c "Full_User_Name"
Optional. This is an optional comment field but is generally used to hold the user's full name so the account can easily be identified. The Full_User_Name must be wrapped in quotations if it contains spaces.
User_Name
The user name of the account you would like to add. This must be unique and will be the account name that is used to log in.
NOTE: In this tutorial we will not be specifiying the -d parameter. This tells the system to use the default directory path of /home/User_Name for the home directory.

Prerequisites

To complete this tutorial you will require a running Ubuntu Linux Server 16.04 LTS system and an account with sudo administrative privileges. The sudo command is used to provide the superuser privileges required for the useradd command.

Create a User

The following steps will guide you through creating a user on an Ubuntu Linux Server 16.04 LTS system.

  1. To begin adding a new user to your system, you will need to be logged in using a valid user account for your system. If you are unsure of how to do this, read our tutorial on Logging into Ubuntu Linux Server 16.04 LTS.

    In this tutorial, we have logged in as techonthenet on the host called ubuntu.

  2. We will add a new user called tsmith which has a User ID of 20000, a home directory of /home/tsmith and is a member of the group called professors which has a Group ID of 11000.

    To add the user called tsmith, we would enter the following command:

    sudo useradd -u 20000 -g 11000 -m -c "Tom Smith" tsmith

    The following screenshot demonstrates what you will see.

    Add user

    When you have entered the command, press the Enter key to execute the command.

  3. The sudo command will now prompt you to enter the password for your administrator account.

    Enter sudo password

    Please note that no characters will show as you type your password. This is normal and is important to preserve the security of your password.

    After you have entered your password, press the Enter key to continue.

  4. If all goes well, you will see the system prompt appear again without any errors. This indicates that the new user called tsmith has been added successfully.

    After user added

  5. In this step we will check to ensure that the new user called tsmith was added to the system. Since new users are added to the end of the system passwd file called /etc/passwd, we can use the tail command to verify that the new user was added.

    Enter the following tail command after the system prompt to show the last few lines of the system passwd file:

    sudo tail /etc/passwd

    The following screenshot demonstrates what the command will look like after it is typed.

    Tail passwd file

    When you have entered the command, press the Enter key to execute the command.

  6. As seen in the screenshot below, the following line appears at the end of the /etc/passwd file indicating that the tsmith user was created.

    tsmith:x:20000:11000:Tom Smith:/home/tsmith:

    Confirm user added

  7. After creating a new user it is very important to assign a password to the new account. To set a password for the tsmith account enter the following command after the system prompt:

    sudo passwd tsmith

    The command will look like the following:

    Set user password

    When you have entered the command, press the Enter key to execute the command.

  8. The passwd command will now prompt you to enter the password you would like to associate with the tsmith account.

    Enter user password

    Enter the password and press the Enter key when done.

  9. The passwd command will now prompt you to re-enter the password to ensure that the passwords match.

    Re-enter user password

    Re-enter the password and press the Enter key when done.

  10. If all goes well, you will see the following line appear as it does in the screenshot below:

    passwd: password updated successfully

    This indicates that the password was successfully changed.

    User password set

    Congratulations, you have successfully added a new user to your Ubuntu Linux Server 16.04 LTS system!