How-To

How to Add or Delete a User in Ubuntu

How to Add or Delete a User in Ubuntu

When you’re administering an Ubuntu PC, you may need to delete or add a user. If so, this guide shows you how to do it.

If you’re sharing your Ubuntu PC with other users, it’s a good idea to create an account for each user. That’ll allow each user to personalize their account the way they want. Each can have their own background, settings, and browser favorites. If any user stops using your PC, you should consider deleting that account, too. You can easily add or delete a user on Ubuntu using the terminal by following the steps below.

How to Add a New User Account on Ubuntu

On an Ubuntu PC (and, indeed, on most Linux distributions), user accounts can have different levels of access and permissions. Each user gets a specific ID number called a user ID (or UID) and their own home directory, where they can store their personal files.

From time to time, you might need to add a new user. This is easily done from the terminal using the adduser command. You’ll need root access to do this—you can elevate the command using sudo. To add a new user account on Ubuntu, follow these steps.

  1. Open a new terminal window.
  2. Type sudo adduser user, replacing user with the desired username, and press Enter.
  3. You’ll be prompted to create and verify a password for the new user—follow the on-screen instructions to do this.
  4. Follow the prompts to fill out the new user’s information. You can skip this by pressing Enter for each prompt.
    Adding a new user on Ubuntu
  5. Once completed, the new user will be ready to use their account.

How to Grant a User Root Access on Ubuntu

If you’ve recently created a new user account and want to give it root-level access on your Ubuntu PC, you can do so by using the usermod command. Granting root access to a user on Ubuntu means adding the user to the sudo group, meaning they can elevate their commands to run as root.

Allowing users to run commands as sudo presents certain risks, as they’ll be able to access any file or folder on your PC and make any change they want to your system. Only grant a user with superuser permissions if you trust them—otherwise, leave them with standard user access.

To grant root access to a user on Ubuntu, follow these steps.

  1. Open a new terminal window.
  2. In the terminal, type sudo usermod -aG sudo user, replacing user with the correct username, and press Enter.
  3. To verify the user has been added to the sudo group, type groups user and press Enter, replacing user with the username. This should list that the user is now a member of the sudo group.
    Granting sudo access

How to Remove a User Account on Ubuntu

If you’re looking to remove an Ubuntu user account, you can use the deluser command (as long as you have root access using sudo). You can use this command to remove the user and keep their home directory intact. Alternatively, if you want to remove their files, you can use it to wipe their home directory, too.

To remove an Ubuntu user, follow these steps.

  1. Open a new terminal window.
  2. Type sudo deluser user to remove the user account without deleting their home directory. Replace user with the correct username before you press Enter and provide your password, if prompted to do so.
    Deleting a user on Ubuntu
  3. If you want to delete the user’s home directory, too, type sudo deluser --remove-home user (replacing user with the correct username) and press EnterDeleting an account (with their files)
  4. Next, type id user (replace user with the correct username). If the command is successful and returns a value, the username still exists, and you may need to repeat the process. If it fails with a no such user error message, then the user account has been successfully deleted.
    An example of the id command on Ubuntu failing to find a deleted user

Managing Access to Your Ubuntu PC

Using the steps above, you’ll be able to quickly manage the access to your Ubuntu PC by adding and deleting users, when necessary. Adding a new user account is simple, but if you decide to delete an account, make sure to back up any files from their user folders first—you may lose them in the process.

Make sure to control who has root-level administrative access, too, depending on who is planning on using your PC.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

 

To Top