User Management on Ubuntu 20.04: A Beginner-Friendly Guide

Managing user accounts on a Linux system is a key task for any system administrator. When setting up a new system, you often start with root access, which provides complete control but can also be risky if used carelessly.

Instead, creating separate, unprivileged user accounts is safer and more efficient. These accounts ensure that each user has their own access, reducing the risk of accidental changes to the system. For administrative tasks, Ubuntu offers the sudo tool, which allows specific commands to be run with elevated privileges.

In this guide, you’ll learn how to:

  • Add new users
  • Grant users sudo privileges
  • Delete user accounts
  • Ensure secure and effective user management

Prerequisites

Before starting, ensure the following:

  • You have access to a server running Ubuntu 20.04.
  • You have root access or a user account with sudo privileges.
  • The server’s firewall is enabled.

Adding a New User

To add a new user, follow these steps:

If Logged in as Root:

Run the following command:

adduser newuser

If Logged in as a Non-Root User with sudo Privileges:

Use the sudo command:

sudo adduser newuser

Setup Process:

You’ll be prompted to:

  1. Assign and confirm a password.
  2. Enter optional user details (press ENTER to skip any fields).
  3. Confirm the information by pressing Y.

The new user is now ready and can log in using the password you created.

 

Granting sudo Privileges

If your new user needs administrative rights, you can grant them sudo privileges. There are two methods to achieve this:

1. Add the User to the sudo Group

On Ubuntu 20.04, users in the sudo group have administrative privileges.

Check the user’s current groups:

groups newuser

To add the user to the sudo group:

sudo usermod -aG sudo newuser

2. Grant Explicit Privileges in /etc/sudoers

Use the visudo command to safely edit the sudoers file. This prevents misconfigurations.

Run:

sudo visudo

Locate the line:

root    ALL=(ALL:ALL) ALL

Add the following line beneath it (replace newuser with the username):

newuser ALL=(ALL:ALL) ALL

Save and exit by pressing CTRL + X, then Y, and finally ENTER.

 

Testing sudo Privileges

To verify that the user can use sudo, log in as the new user and run:

sudo some_command

You’ll be prompted to enter the user’s password. If successful, the command will execute with administrative privileges.

 

Deleting a User

If a user account is no longer needed, you can remove it:

Delete the User (Without Files):

sudo deluser newuser

Delete the User and Their Home Directory:

sudo deluser --remove-home newuser

Remove sudo Privileges (if configured in /etc/sudoers):

Edit the sudoers file:

sudo visudo

Remove the line for the deleted user:

newuser ALL=(ALL:ALL) ALL

Save and exit the file.

 

Best Practices for User Management

  1. Create Separate Accounts: Ensure each user has their own login to maintain accountability and security.
  2. Use sudo Wisely: Only grant sudo privileges to users who need administrative access.
  3. Audit Users Regularly: Periodically review user accounts and remove unused ones.

Conclusion

Effective user management is essential for maintaining a secure and organized Linux system. By learning how to add, modify, and remove users, you’ll ensure your system remains safe and efficient. Whether you’re managing a single server or multiple systems, these practices will set a strong foundation for administration.