How to Add and Delete Users on Ubuntu 22.04

Published on April 13, 2024

In Linux, numerous users can access the same system but with different user accounts. As the administrator, your task is to add users and specify what roles they should have based on their privileges.

When you install Ubuntu 22.04, the root account is the default user account. While it’s possible to only use the root account, it’s a bad idea as commands you run as the root user can be destructive. Again, creating a low-privileged user account is better if you share the system with someone. That way, some tasks are only left to the root account. Stick around as we explore all the steps to add and delete users on Ubuntu 22.04

Two Methods to Add and Delete Users on Ubuntu 22.04

Only a root user can add users on Ubuntu. So, the first step is to ensure you have root access to your system. Once you do, you can add users on Ubuntu 22.04 using the command line or the GUI. Let’s go through each method.

Method 1: Via Command-line

You need the following steps when adding a user via the command line.

Step 1: Add the User

What username do you want to use for the new user? Once you decide on it, utilize the below syntax to add the user.

Copy

We’ve created ‘new-user’ for our case. You don’t need to include sudo if you are running as root. However, include it if you run a non-root account with sudo privileges.

You will get an output showing the user has been added and their group has been created.

You then need to add the newly added user’s details. First, you must add their login password. You can then optionally add their other information, such as their full name.

Lastly, confirm that all details are correct by typing ‘y’ and pressing the enter key.

Step 2: Add the User to sudoers

Every Linux user is associated with a group. A new group

is created for new users. You can verify this using the below syntax.

Copy

Based on the output above, we confirm that our user is yet to be added to the sudoers group. As such, the user can’t perform administrative tasks.

Let’s first switch to the new user using the su command to prove this.

Copy

We will get an error even when we try running a simple update command that requires sudo. This error occurs because the new user does not have root privileges.

To change this, add the new user to the sudoers file using the below syntax.

Copy

Rechecking the group, our user is now part of the sudo group.

We can now run commands with sudo without getting any error.

Step 3: Delete the User

We’ve seen what it takes to add users on Ubuntu 22.04 via the command line. The last step is understanding how you can delete the added users.

To delete users, we will use the deluser command below.

Copy

The above command manages to delete the specified user but doesn’t delete the user’s home directory.

A better way is to delete the user and their home directory, which you can achieve using the command below.

Copy

Method 2: How to Add and Delete Users on Ubuntu 22.04 via GUI

You don’t have to use the command line to add and delete users on Ubuntu 22.04. However, if you are working with a server, the command line is your best bet. If you can access the GUI, add users using the steps below.

Step 1: Open Settings

On your Ubuntu 22.04, access the applications and open Settings.

Step 2: Navigate to Users

Once the settings page opens, scroll down on the left sidebar and click the Users option.

On the user page, click the unlock button at the top right.

You must enter your password to unlock the feature.

Step 3: Add the User

After unlocking the feature, the Add User button will appear. Click on it.

Next, add the details for the new user, such as their username and password. Under the Account Type, we are creating a standard user with basic privileges. If you want a user with root privileges, select the administrator option.

Once you’ve added the details, click the Add button to complete the process.

Your new user will be added, and their profile will appear on the page.

Step 4: Deleting the User

Below the target user, locate and click on the Remove User button. You will get prompted to confirm deleting their files.

That’s how you add and delete users on Ubuntu 22.04.

Conclusion

Adding and managing users is an administrative task for the root user account. You can add and delete users in two ways. You can use the command line or graphically. Use the method you are comfortable with, depending on your situation, and set the appropriate privileges for the new user.

New to LinuxMeta? Get Started Now! 

Instantly Deploy Linux & Windows KVM VPS at a Cheap Price