Main Menu

How to Add and Manage Users on Ubuntu: Step-by-Step Guide 

Adding and removing users in Ubuntu is one of the tasks that can only be performed by the Linux administrator. In Ubuntu, just like other Linux distributions, each user with a different permission level can perform specific configurations through the Command Line interface or the Graphical User Interface. In this article from the Ubuntu training section on the Pars Pack blog, we intend to examine how to add and remove users in Ubuntu. If you are a Linux user, especially a user of the Ubuntu distribution, reading this article will help you learn how to add and remove users in Ubuntu.

The essential prerequisite for adding and removing users in Ubuntu

To perform actions such as adding and removing users in Ubuntu, you need root access to the Linux server. However, performing configurations with root access is very sensitive, and in some cases, it may cause trouble for you. In other words, it becomes like the story of the barber who blinds the customer while trying to shape the eyebrows.

To prevent this from happening, the best solution is to create a user account without additional permissions. Then, for actions that require administrator approval, use sudo privilege instead of root access. In any case, to remove and add users in Ubuntu, you will need either root access or sudo privileges.

If you're new to the platform and want a clearer understanding before managing users, check out our guide on What is Ubuntu to get started with confidence.

Methods to Add Users on Ubuntu

So now let's look at the most common ways to add a user in Ubuntu.

1. Adding users in Ubuntu through the command line

 To add a user in Ubuntu, open the command window using the shortcut keys Ctrl plus Alt plus T. If you are logged in as the main user, you can create a new user by running the following command:

adduser newuser

The Adduser command is a type of Perl script that makes adding users in Ubuntu easier. As you can see, using it is simple and does not have any particular complexity. Instead of the word newuser, you can place the actual name of the person.

If you are logged in as a user without root access, by adding the sudo command at the beginning of the command line, you can create the new user account:

sudo adduser monovm

The output that will be shown to you is as follows:

Adding user `username’ … Adding new group `username’ (1001) … Adding monovm `username’ (1001) with group `username’ … Creating home directory `/home/username’ … Copying files from `/etc/skel’ …

Then you will be asked a series of questions. You only need to enter the new password because answering the remaining questions is optional. The output will be as follows:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y n]

As you can see, after setting the new password and retyping it, you can skip the user information section by pressing the Enter key while creating a user in Ubuntu. Finally, to confirm the accuracy of the information, press Y and the new user will be created. In this way, you have successfully created the user’s home directory. Now the new user can copy files into the directory located at /etc/skel or write or edit them.

If you intend to give the user permission to perform some administrative tasks, you must grant sudo privileges to that user. In the continuation of the article, we will explain how to do this.

2. Add a User to a Sudo Group with Usermod

After adding users in Ubuntu, if you want to give a new user root-level access, you must grant it through Sudo. First, add the user to a group that has Sudo privileges. In Ubuntu 20.04, any member of the Sudo group receives full administrative rights. Now, use the following command to check which groups the new user belongs to:

groups monovm
The output that it shows us is as follows:

monovm : monovm

According to this output, the user named monovm is placed in a new group that has the same name as the user. By Ubuntu default, when a new user is created, a group with the same name is also created and the user is added to it. To add the user to a new group with Sudo access, enter the following command:

sudo usermod aG sudo monovm

In this command, the -aG option adds the user to the group list using the usermod command. Since usermod also requires Sudo privileges, you can run it only when logged in as a user with Sudo or root access. By adding sudo at the start of the command, the new user (here, monovm) will be added to the group with Sudo privileges.

If you’d like to verify all existing users and their group memberships in more detail, take a look at our complete guide on list users and groups on Ubuntu for quick reference.

3. Adding a user through the graphical interface

By following the six steps below, you can easily add a user to Ubuntu through the graphical interface:

  1. Enter the Ubuntu settings section. From the system settings menu and by right clicking on the Ubuntu system, go to the Settings section.

  1. In the menu on the left side of the page, click on the Users section.

  1. Click on Unlock in the upper left corner of the page.

  1. Enter your password. After that, the settings will open and you will be able to create a new user.

  1. Now the Unlock button has changed to a green Add User button. Click on it and create the new user based on the type of account and access.

  1. Step six: After completing the settings, by clicking the Add button, you will successfully add the new user in Ubuntu.

The popularity of the graphical interface is so high that for users who do not have a good relationship with the Linux command line, it has become a highly preferred and primary alternative.

Assigning privileges to each user using the Visudo command

If you want to give each user a specific privilege and access level in a precise way, you can do this using the Visudo command. With this command, a configuration file named etc sudoers is opened in the system’s default editor. In this file, the privileges of each user are clearly defined. Similar to the commands above, if you are logged in with root access, use the following command:

Visudo

If you are logged in with Sudo access and without root access, use the following command:

sudo visudo

Now find the following line:

root ALL=(ALL:ALL) ALL

Below this line, enter the following command:

newuser ALL=(ALL:ALL) ALL

Replace the word newuser with the username of the person you want to give Sudo access to. For example, here we will place a user named monovm:

Monovm ALL=(ALL:ALL) ALL

In the same way, add the name of any user to whom you want to grant Sudo access below this line. Finally, save the file and press the key combination CTRL plus X. By pressing the key Y and then pressing Enter, your file will be saved.

Visudo vs Usermod 

You might be wondering whether it is better to use Visudo or Usermod when creating a user in Ubuntu and assigning Sudo access to that user. The answer is that using the Visudo editor is the only method that allows you to make changes in the etc sudoers file. With this command, the file is locked against simultaneous edits, and as a result, to prevent issues that may arise from losing Sudo privileges due to incorrect configuration, this command acts like a safety parachute. 

To move between accounts after setting permissions, see our quick guide on How to Switch User in Linux.

Removing Users in Ubuntu

In this section, we will cover the main methods for removing junk in Ubuntu, including the command line and the graphical interface.

1. Deleting users in Ubuntu through the command line

If you intend to delete a user in Ubuntu, you can easily remove the user using the Deluser command. Similar to adding users in Ubuntu, if you are logged in with root access, enter the following command:

deluser monovm

If you are logged in with Sudo access and without root access, type the following command:

sudo deluser monovm

With the following command, you can also delete the user’s home directory privileges:

sudo deluser remove home monovm

If you have set specific privileges for the user, you can remove them with the following command:

sudo visudo
root ALL=(ALL:ALL) ALL
Monovm ALL=(ALL:ALL) ALL DELETE THIS LINE

By doing this, no new user who is created with the same name will accidentally be given Sudo access.

2. Deleting a user through the graphical interface

To delete a user in Ubuntu, simply right click on the desktop and enter the Settings panel.

  1. like the process we followed in the previous section, go to the Users section on the left side of the settings panel and click on the Unlock tab.

  1. After entering your password and unlocking the settings, select the account you want to delete and click on the red Remove Users button.

  1. In the final step, you will be asked whether you want to keep the user account files including the home directory or not. If you want to keep the files, click on the Keep File option, and if you want to delete the user along with all of the files, click on the Delete Files option.

In this way, you will be able to perform the process of adding and deleting users in Ubuntu within the popular graphical interface environment.

Editing Users in Ubuntu

After creating a user, you may need to modify some of their settings. For this purpose, the main tool you will use is the usermod command.

Change the username

Use the -l option to assign a new username:

sudo usermod -l sara ali

In this example, jane is the old username and sara is the new one.

Change the user’s primary group

Use the -g option to set a new primary group:

sudo usermod -g developers sara

(Make sure the developers group already exists.)

Change the default shell

To modify the user’s login shell, use the -s switch:

sudo usermod -s /bin/bash sara

Change the password

To update a user’s password, run:

sudo passwd username

Overall, usermod is a powerful tool that enables precise customization and management of user settings, helping you maintain better control of your system.

For a deeper look into password management and secure credential updates, you can refer to our detailed guide on Change user password in Ubuntu

Best practices for user management in Ubuntu

User security management is a continuous process that requires following a set of best practices.

1. Enforcing the principle of least privilege (PoLP)

You should not give all users full sudo group membership by default, as this grants the ability to perform anything on the system. If a user only needs a few high-privilege tasks, like restarting a specific web service, it is better to configure the etc sudoers file precisely instead of granting full sudo access. Using visudo, you can define exactly which commands each user can run and how.

2. Regular auditing and cleanup

Periodically review all active user accounts and the membership list of critical groups, especially the sudo group. Remove accounts that are no longer needed, or at least lock them to prevent unauthorized access. Cleaning up unnecessary and redundant groups is also part of this process.

3. Protecting physical access

Anyone with physical access to the machine can bypass password-based security by modifying the GRUB boot loader. Therefore, if your server or desktop is located in a public or untrusted environment, you must protect the GRUB boot loader with a password to prevent physical access attacks. This ensures that even if an attacker gains physical access to the device, they cannot enter Recovery Mode or access the root shell.

4. Using strong authentication and staying aware of security practices

Always encourage users to choose strong passwords. A password should be at least twelve characters long and contain a mix of uppercase letters, lowercase letters, numbers, and symbols. In sensitive environments, implementing multi factor authentication for login and sudo access is a necessary security measure.

If you ever need full administrative control for advanced tasks, you can refer to our guide on How to Enable Root Account in Ubuntu.

Ready to Manage Users More Efficiently?

In this article, we covered all the essential aspects of adding and managing users in Ubuntu. You learned how to create new users, change passwords, add or remove users from groups, and edit or delete accounts when needed. Finally, if you want to apply these skills on a secure, fast, and always-available server, I highly recommend checking out our Ubuntu VPS service at MonoVM. Powered by NVMe SSD for higher speed, unlimited bandwidth, the latest Ubuntu LTS versions, 24/7 support, and a 99.9% uptime guarantee, it’s an excellent choice for launching professional projects, software development, and managing enterprise servers.

People also read: 

Category: Linux Tutorials

Write Comment