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

Configure a Static IP Address on Ubuntu 18.04: Netplan Guide

Setting a static IP address on your server is a smart move. It ensures your…

1 hour ago

Install Xrdp on Ubuntu 18.04: Remote Desktop Setup Guide

Xrdp is an open-source implementation of the Microsoft Remote Desktop Protocol (RDP). It lets you access…

1 hour ago

Install Wine on Ubuntu 18.04: Run Windows Apps on Linux

Wine (short for "Wine Is Not an Emulator") is a compatibility layer that lets you run…

2 hours ago

Install KVM on Ubuntu 18.04: Setup, Network, and Create VMs

KVM (Kernel-based Virtual Machine) is an open-source virtualization technology built into the Linux kernel. It lets…

2 hours ago

Upgrade to Ubuntu 20.04 LTS: Prepare, Update, and Confirm

Ubuntu 20.04 LTS (code name Focal Fossa) was released on April 23, 2020. It is a…

1 day ago

Install Google Chrome on Ubuntu 20.04: Download and Setup Guide

Google Chrome is the most widely used web browser in the world. It is fast, secure,…

1 day ago