What you will read?

Managing users on Ubuntu is a core task for system administrators, developers, and VPS owners. Whether you’re setting up a secure environment for your team or cleaning up unused accounts, knowing how to add and delete users properly ensures better control, security, and performance.

Step 1: Add a New User with

The adduser command is the most user-friendly way to create a new account on Ubuntu. It automatically sets up the home directory, shell, and prompts for a password and user details.

sudo adduser newusername

Step 2: Add a User with (Advanced)

The useradd command is more flexible and script-friendly but requires additional flags to configure the user properly. It’s commonly used in automated deployments or VPS provisioning.

sudo useradd -m -s /bin/bash newusername
sudo passwd newusername

Step 3: Grant Sudo Access to a User

To allow a user to run administrative commands (like installing packages or restarting services), you need to add them to the sudo group.

sudo usermod -aG sudo newusername

Step 4: Delete a User with deluser

When a user no longer needs access, you can remove their account while keeping their files intact. This is useful for auditing or transferring data later.

sudo deluser oldusername

Step 5: Remove User and Home Directory

When a user account is no longer needed and you want to fully clean up their data, you can delete both the account and its associated home directory to free up space and maintain system hygiene.

sudo deluser --remove-home oldusername

Step 6: Delete a User with  (Advanced)

The userdel command is a lower-level alternative to deluser, often used in scripts or minimal environments.

sudo userdel oldusername

To remove the user’s home directory as well:

sudo userdel -r oldusername
Read more: Securing PostgreSQL Databases on VPS: A Step-by-Step Guide

Step 7: List All Users on the System

To audit user accounts or verify access on your Ubuntu server, you can list all registered users by reading system files or using built-in commands.

cut -d: -f1 /etc/passwd

Sure! Here’s a short, SEO-friendly intro for that command:

getent passwd | cut -d: -f1
Read more: MySQL Replication Setup on VPS: Step-by-Step

Step 8: Check User Groups

To see which groups a user belongs to — including whether they have sudo access — use the groups command.

groups newusername