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

Install VirtualBox on Ubuntu 18.04 from the Oracle Repository

VirtualBox is a free, open-source, cross-platform virtualization application maintained by Oracle. It lets you run multiple…

6 hours ago

Install PostgreSQL on Ubuntu 18.04 with Remote Access Setup

PostgreSQL (also called Postgres) is a free, open-source, object-relational database management system with a strong reputation…

6 hours ago

Install VMware on Ubuntu 18.04: Workstation Player Setup Guide

VMware Workstation Player is a mature, stable virtualization platform that lets you run multiple isolated operating…

6 hours ago

Set Up a UFW Firewall on Ubuntu 18.04: Allow, Deny, and Manage

A properly configured firewall is one of the most important layers of security for any internet-facing server. UFW (Uncomplicated Firewall) is a user-friendly front-end for managing iptables rules that ships pre-installed on Ubuntu. Its defaults are sensible: block all incoming connections, allow all outgoing connections. No outside traffic reaches your server unless you explicitly open a port. This guide covers how to configure a UFW firewall on Ubuntu 18.04, from setting default policies and application profiles to writing allow and deny rules for specific ports, IPs, and subnets. <strong>Prerequisite:</strong>&nbsp;You&nbsp;need&nbsp;sudo&nbsp;access. Configure UFW Firewall on Ubuntu: Defaults, SSH, and Application Profiles If UFW is not installed, add it with: bashsudo…

6 hours ago

Disable UFW Firewall on Ubuntu 18.04: Stop, Reset, and Re-enable

UFW (Uncomplicated Firewall) is a user-friendly front-end for managing iptables rules on Ubuntu. It ships pre-installed…

6 hours ago

Install Apache Cassandra on Ubuntu 18.04: NoSQL Setup Guide

Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with…

1 day ago