Home  »  ArticlesGuidesTechnology   »   How to Add Users on Ubuntu 20.04 With adduser Command-line Tools

How to Add Users on Ubuntu 20.04 With adduser Command-line Tools

Here we will be showing you how to add users to Ubuntu 20.04. In all fairness, the steps here also apply to previous Ubuntu versions and even other Linux distros. Adding users to any Linux system is a simple but very important task to do while setting up your system.

By default, a fresh installation of Ubuntu gets you one user who happens to be the root user. This user has administrative rights on your system and that makes it potentially very destructive if used wrongly or in the hands of unauthorized users.

The general rule is to create at least one other user with sudo privileges that can perform administrative tasks on-demand using the sudo command. This is the user you would generally use to sign into the system.

Prerequisites

Because we are using Ubuntu 20.04 in this guide, you will need to have authorized root access to a server running Ubuntu 20.04. If you haven’t already, you can set this up using this initial server setup guide for Ubuntu 20.04.

Add Users

When signed in as the root user, create a new user at any time by typing the following:

# adduser newuser

Or if you are signed in as a non-root user then use the following command:

$ sudo adduser newuser

Where newuser is the username you are planning to use. You will then be presented with a series of prompts requiring you to:

  • Assign and confirm a password for the new user
  • Enter any additional information about the new user. This is completely optional and can be skipped by hitting ENTER if you don’t wish to utilize the specific option.
  • Finally, you will be asked to confirm that the information you provided was correct by entering Y to continue.

Your new user is now ready for use and you can log in to the system using the password that you set. This user will not have any root (administrative) privileges. if you want administrative rights activated you can do so by following the next step.

Grant Sudo Privileges to a User

To grant user root (administrative) privileges they need to be given access to sudo by adding the user to a pre-defined sudo user group. By default on Ubuntu systems, any user in the sudo group is extended full system privileges.

You can verify what groups your new user is in by running the following groups command:

$ groups newuser

With the following output expected

newuser : newuser

By default, adduser command creates a group with the same name as the new user and places the user in that group. To add the user to another existing group we can run the following usermod command:

$ usermod -aG sudo newuser

The -aG option here tells usermod to add the specified user (newuser) to the listed groups (sudo).

Specifying Explicit User Privileges

You can explicitly specify privileges on a per-user basis by editing the /etc/sudoers configuration file. This should be done using the visudo command and not directly that way it locks the file against multiple simultaneous edits and performs a sanity check on its contents before overwriting the file. This protects a situation where you misconfigure sudo and are locked out from fixing the problem because you have lost sudo privileges.

If you are currently signed in as root, type:

# visudo

Or, if you are signed in as a non-root user with sudo privileges, type:

$ sudo visudo

visudo will open /etc/sudoers in the system’s default editor which is usually nano.

Search for or scroll to the line that reads as follows:

root ALL=(ALL:ALL) ALL

Add a new matching line below it but change root to your new user to look something similar to the example below:

root ALL=(ALL:ALL) ALL
newuser ALL=(ALL:ALL) ALL

root ALL=(ALL:ALL) ALL<br>newuser ALL=(ALL:ALL) ALL

Repeat for any additional user that you would like to assign sudo privileges. When you are done save and close the file by hitting CTRL+S then CTRL+X. You can also just hit CTRL+X, followed by Y, and then ENTER to confirm.

Your new user is able to execute commands with administrative privileges. You can test this by running a command with elevated privileges:

$ sudo command

You will be prompted to enter the user’s password.

Next, we will show you how to delete users on Ubuntu 20.04.

Conclusion

You should now have a good idea of how to add users to Ubuntu 20.04 with adduser and visudo command-line utilities. You should also be able to manage those users by elevating them with root or administrative privileges. You can also find out how to delete users on your Linux system here as well as delete user groups on the Linux system.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Guides, Technology