How To

Add and Delete Users on Ubuntu 18.04: A Practical Guide

Managing user accounts is one of the most basic system administration tasks on any Linux server. On Ubuntu 18.04, you can add, modify, and remove users directly from the command line using simple built-in tools.

This guide shows you how to add and delete users on Ubuntu 18.04 and how to grant a new user sudo privileges.

Prerequisite: You need root or sudo access to manage user accounts.

Add a New User on Ubuntu

The adduser command creates a new user account and sets up their home directory automatically.

To add a new user named john:

bashsudo adduser john

The command walks you through a short setup process. It will ask you to set and confirm a password, then optionally fill in some basic profile details like full name and phone number. Press Enter to skip any field you do not want to fill in.

The new user’s home directory is created at /home/john, and a set of default configuration files is copied into it automatically.

Grant Sudo Privileges to a User

By default, new users do not have administrative access. To give a user sudo privileges, add them to the sudo group:

bashsudo usermod -aG sudo john

To confirm the change worked, switch to the new user and run a command with sudo:

bashsu - johnsudo whoami

Output: root

If you see root, the user has sudo access.

Delete a User on Ubuntu

To remove a user account without deleting their home directory and files:

bashsudo deluser john

If you want to remove the user and delete their home directory and all their files at the same time:

bashsudo deluser --remove-home john

Use the --remove-home flag carefully. Once deleted, those files cannot be recovered unless you have a backup.

Check All Existing Users

To see a list of all user accounts on the system, print the /etc/passwd file:

bashcut -d: -f1 /etc/passwd

This shows every account, including system accounts. Regular user accounts typically start from UID 1000 and above.

User management on Ubuntu is straightforward once you know the right commands. Use adduser to create, usermod to modify, and deluser to remove accounts. Got questions? Leave a comment below.

Cyber Defence

Recent Posts

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

1 week ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

1 week ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

1 week ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

2 weeks ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

2 weeks ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

2 weeks ago