Similar to Windows and Mac, Linux is a multi-user operating system that endorses numerous users, each with its own distinct user accounts. It is not recommended for a single user to manage the entire system, particularly in a production environment. It is always advisable to have multiple users in your system. 

Occasionally, you may require a user to act solely as a service account, with no home folder, no shell access, and only the ability to execute specific applications and tools. This guide will demonstrate the various methods to create a user account in Ubuntu Linux using both the GUI and the terminal.

Create a new user on Ubuntu using GUI

This method of adding a user through the GUI is simple and straightforward, but it has limitations regarding available options. Nonetheless, it can be a useful option for those who prefer to work with a graphical interface.

To create a new user through the graphical user interface, abide by these instructions. This illustration portrays the utilization of the GNOME shell, which is the default desktop environment. 

  •  On the Ubuntu desktop, click the Show Applications button or press the Super key () on your keyboard.
  • Enter "settings" in the search field and select the pop-up icon. 
  • Proceed to Users → Unlock → input your password → Verify to unlock the Users settings.
  • Once you have accessed the User settings, select the Add User option in the window's upper section. 
  • Input the necessary details about the user you intend to create. Once you have reviewed and confirmed the accuracy of the user's information, select the Add button positioned at the top right-hand corner of the screen.
    • Type of account: Select whether you want to create a user account in Standard or Administrator in Ubuntu. A standard user has restricted access to the system, while an administrator has unrestricted access. 
    • Full name: The complete name of the user. 
    • User ID: The username for the new account. 
    • Password: Decide whether to Permit the user to select a passcode during the next login or Set a passcode now. In case you choose the second option, please insert the new passcode into the related field and confirm it.
  • Select the recently created user account to view its attributes. This section permits you to adjust the settings of the user account, including: 
    • Altering the username
    • Converting the account category to Standard or Administrator 
    • Modifying the Language
    • Adjusting the password
    • Activating or deactivating automatic login (mandating or not mandating a password to sign in)
    • Inspecting the user's activity records (login periods as well as sessions)
    • Deleting the user account

Create a new user on Ubuntu via Command Line

Although using the graphical user interface to create a user account in Ubuntu may seem easy, it comes with limited options. On the other hand, doing the same through the command line provides greater flexibility and control over the provisioning process. So, what are the advantages of creating users through the command line? 

Since Ubuntu computers, particularly servers, lack a desktop environment, the command line is the only option. Creating a user account through the command line unlocks additional options unavailable in the GUI. The command line enables automation, such as user account provisioning workflows or bulk user creation.

Creating a new user with a Default Home Directory Path

Follow these steps:

  • To launch a terminal window on a desktop interface, hit the key combination of CTRL+ALT+T. In case of a non-desktop interface, access Ubuntu by logging in through your preferred SSH client. 
  • Creating a new user on Ubuntu involves a privileged task that necessitates elevation. Switch to the current root shell to prevent the need to run every command with the sudo prefix.
  • Execute the below command to include a typical user named john_user1. Choose an alternate username of your preference. The -m parameter instructs the system to generate a home directory for this user. The default location for the home directory is /home/<username>, in which the username indicates the name you have given the new account.

Create a standard user account.

useradd -m john_user1

To make the newly created user an administrator, use the -G sudo parameter. The -G parameter signifies that you are enrolling the new user as a part of the sudo group.

Create an administrator user account.

useradd -m john_user1 -G sudo

  • Now you must possess a freshly created user account. This user has a home directory in the default location. Execute the following command to display the home directory of the new user.

ls -la /home/ john_user1

In addition, if you desire to include the newly created user in a specific group, you can use this command:

sudo usermod -aG cdrom john_user1

? Unleash your website's true potential with our cutting-edge Linux VPS hosting solutions! Scale effortlessly and reach new heights in the digital world. ???

Create a user account in Ubuntu with a Custom Home Directory Path

The predetermined home directory for new user accounts is located at /home/. If you wish to create a new user on Ubuntu with a personalized home directory, you can execute the -d or --home-dir option. These two options are identical and can be used interchangeably. 

To create a new user, for example, tmp_user, with a home directory located under /tmp/home, use the following command: 

useradd -m -d /tmp/tmp_user tmp_user

Don’t forget that the parent directory of the custom home must be present before creating the user account.

Create a user account in Ubuntu with a specific UID

The system typically creates a random unique user identification number (UID) for a new user. However, certain situations may necessitate the allocation of a predetermined UID, such as transferring users from a different system or duplicating application settings that depend on distinct UIDs. 

To generate a new user with a specific UID, you must enable the -u flag, followed by the desired UID.

useradd -u 1234 uid_user

Authenticate the recently added user's UID by executing the id command, which displays details about the present user, encompassing the UID.

id uid_user

Create a new user on Ubuntu with an expiration date

In certain instances, it may be necessary to make a new user account that will only be granted temporary access to the system. Once the designated time period has elapsed, the user can no longer log in to the system. 

This approach is particularly useful when an individual assists with a project and requires access only during specific dates. Linux offers a solution to this issue by enabling users to set an expiry date for an account using the -e flag, followed by the date in the YYYY-MM-DD format. 

For example, you can use the following command to generate a user account named temp_user which will be expired on June 30, 2024:

useradd -e 2020-06-30 temp_user

Authenticate this user by executing the chage command plus the -l flag. This command showcases details regarding the duration of time before a user's password expires.

chage -l temp_user

Conclusion

Do you require to grant somebody entry to your Ubuntu desktop for a limited period? Or do you supervise an Ubuntu server and require to establish a new user account for a new colleague? Irrespective of the grounds, there are numerous approaches to generating a user on Ubuntu.

Throughout this guide, you have acquired the knowledge of generating a user in Ubuntu utilizing both the graphical user interface and the command line interface, thus enabling you to opt for the approach that suits you best. 

The graphical user interface method is more user-friendly but has fewer alternatives, whereas the terminal method grants you greater authority and adaptability.

People also read: