How to Add and Remove Users on Ubuntu: Complete Guide
Step-by-step guide to add and remove users on Ubuntu using adduser, deluser, useradd, and userdel, with sudo privileges and home directory tips.

6 min read
Step-by-step guide to add and remove users on Ubuntu using adduser, deluser, useradd, and userdel, with sudo privileges and home directory tips.
- Prerequisites and Supported Releases
- Step 1: Understanding adduser vs useradd on Ubuntu
- Step 2: Adding a New User Interactively with adduser
Operating system security, multi-tenant collaboration, and least-privilege access control all depend on properly configured user accounts. When you manage server infrastructure, knowing how to add and remove users on ubuntu is essential for onboarding team members, setting up isolated service accounts, and revoking credentials when access is no longer required.
Ubuntu provides two distinct toolchains for account administration: friendly, interactive Perl wrappers (adduser and deluser) and low-level POSIX standard utilities (useradd and userdel). Understanding when and how to deploy each tool ensures you can create fully configured home environments interactively or automate user provisioning within bash scripts and Ansible playbooks.
Managing user accounts and system permissions is a foundational skill for Linux server administration. This comprehensive guide covers how to add and remove users on Ubuntu, contrasting interactive tools (adduser, deluser) with low-level binaries (useradd, userdel), managing sudo group memberships, locking accounts, and safely purging user data.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- An active installation of Ubuntu 24.04 LTS (Server or Desktop).
- A user account with active sudo administrative privileges.
- Access to a local terminal or remote SSH session.
Step 1: Understanding adduser vs useradd on Ubuntu
Before executing commands, it is crucial to recognize the architectural difference between Ubuntu's primary user creation commands:
adduser is an interactive Perl script customized for Debian and Ubuntu systems. It automatically creates a home directory, copies skeleton configuration files from /etc/skel, prompts for a password, and sets standard file permissions.
useradd is a low-level compiled system binary available on all Linux distributions. By default, it does not prompt for a password or create a home directory unless explicitly instructed via command-line flags.
| Feature / Behavior | adduser (High-Level) | useradd (Low-Level) |
|---|---|---|
| Default Home Directory | Created automatically (/home/username) | Not created unless -m flag passed |
Skeleton Files (/etc/skel) | Copied automatically (.bashrc, .profile) | Not copied unless -m flag passed |
| Password Assignment | Interactive prompt during creation | Account created locked without password |
| UID / GID Allocation | Selects next available Debian/Ubuntu ID | Selects system defaults |
| Best Use Case | Manual sysadmin and desktop onboarding | Automated shell scripts and CI/CD pipelines |
Step 2: Adding a New User Interactively with adduser
The optional user information fields (GECOS metadata) can be left blank by simply pressing Enter. Once confirmed, the user account is active immediately.
# Add a new user named 'alex' interactively
sudo adduser alex
# Sample terminal interaction:
# Adding user 'alex' ...
# Adding new group 'alex' (1001) ...
# Adding new user 'alex' (1001) with group 'alex' ...
# Creating home directory '/home/alex' ...
# Copying files from '/etc/skel' ...
# New password: [Enter strong password]
# Retype new password: [Retype strong password]
# passwd: password updated successfully
# Changing the user information for alex
# Enter the new value, or press ENTER for the default
# Full Name []: Alex Morgan
# Room Number []:
# Work Phone []:
# Home Phone []:
# Other []:
# Is the information correct? [Y/n] Y
Step 3: Scripted User Creation Using Low-Level useradd
When automating deployments in CI/CD pipelines, container entrypoints, or shell scripts, interactive prompts are disruptive. The useradd command allows non-interactive user creation.
Use the -m flag to create the home directory and -s to specify /bin/bash as the default login shell.
# Create a user non-interactively with a home directory and bash shell
sudo useradd -m -s /bin/bash devops
# Assign an initial password non-interactively or via standard input
echo "devops:SecureTemporaryPassw0rd!" | sudo chpasswd
# Force the user to change their password upon first login
sudo chage -d 0 devops
Step 4: Granting Administrative Privileges via the sudo Group
Never omit the -a flag when running usermod -G. Running usermod -G sudo alex without -a removes the user from all other supplementary groups.
On Ubuntu systems, members of the secondary group named sudo are automatically granted administrative rights to execute commands with elevated privileges.
Add the newly created user to the sudo group using the usermod utility with the -aG (append to group) flags.
# Append user 'alex' to the sudo group
sudo usermod -aG sudo alex
# Verify the user's group memberships
id alex
# Expected output:
# uid=1001(alex) gid=1001(alex) groups=1001(alex),27(sudo)
Step 5: Inspecting User Accounts and Identity Databases
Ubuntu tracks local user accounts, encrypted password hashes, and group memberships across standard system configuration files under /etc/.
You can verify account parameters without opening sensitive files directly by using the getent utility.
# Query account details from /etc/passwd
getent passwd alex
# Output structure: username:password_placeholder:UID:GID:GECOS:home_dir:shell
# alex:x:1001:1001:Alex Morgan,,,:/home/alex:/bin/bash
# Inspect password expiration and aging policy with chage
sudo chage -l alex
Step 6: Temporarily Locking and Unlocking User Accounts
When an employee departs or an account exhibits suspicious behavior, you may want to disable access immediately without deleting their files or home directory.
Locking the account places an exclamation mark (!) in front of the encrypted password hash in /etc/shadow, preventing password logins.
# Lock the user account
sudo passwd -l alex
# Expire the account immediately to prevent SSH key access as well
sudo usermod --expiredate 1 alex
# Unlock the user account and restore access
sudo usermod --expiredate "" alex
sudo passwd -u alex
Step 7: Removing Users Safely with deluser
When you are ready to permanently decommission a user account, use deluser. It provides granular controls for cleaning up user files and group associations.
Depending on your retention policy, you can delete only the user account or purge their home directory and mail spool as well.
Option A: Delete User Account While Preserving Files
This removes the user from /etc/passwd and /etc/group, but leaves /home/alex intact on the disk for auditing or backup.
# Remove the user account only
sudo deluser alex
Option B: Delete User Account and Remove Home Directory
This removes the user and permanently erases their home directory and associated mail spool.
# Remove user, home directory, and mail spool
sudo deluser --remove-home alex
Option C: Remove User and All Files Owned Across the Filesystem
To ensure no orphaned files remain anywhere in /tmp, /var, or shared directories, instruct deluser to scan and remove all matching files:
# Purge user and all files owned across the entire system
sudo deluser --remove-all-files alex
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
userdel: user <username> is currently used by process <pid>.
Cause: The user has active background processes, an open SSH session, or a lingering tmux/screen daemon.
Resolution: Terminate all running processes owned by the user using pkill before re-running deluser.
sudo pkill -u alex && sudo deluser --remove-home alex
useradd: warning: the home directory already exists.
Cause: A previous user with the same name was deleted without removing their home folder.
Resolution: Inspect the existing folder, back up necessary data, and either chown the folder to the new user or delete the legacy directory.
sudo rm -rf /home/alex
User cannot execute sudo commands: '<username> is not in the sudoers file'.
Cause: The user was not appended to the sudo group, or the user has not logged out and back in to refresh group tokens.
Resolution: Append the user to sudo: sudo usermod -aG sudo alex. Have the user log out and log back in.
sudo usermod -aG sudo alex
Security Best Practices and Hardening
Regularly audit /etc/passwd and /etc/shadow for dormant accounts.
Always back up user home directories to a secure archival location before using --remove-all-files to avoid unintended data loss in shared team repositories.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Create a Sudo User on Ubuntu — Learn how sudo privileges and group memberships function on Ubuntu systems.
- How to Add a User to Sudoers in Ubuntu — Configure granular sudoers rules in
/etc/sudoers.d/without modifying main files. - How to Set Up SSH Keys on Ubuntu 24.04 — Deploy secure cryptographic public keys for newly provisioned user accounts.
Authoritative References and Official Documentation

The Linux Command Line, 2nd Edition: A Complete Introduction
Frequently Asked Questions
Quick answers to common questions and configurations
sudo deluser <username> without the --remove-home flag. The user record is removed from /etc/passwd, but /home/<username> remains on disk intact.sudo deluser <username> sudo. This strips their administrative sudo privileges while leaving their user account and personal files intact.--remove-home or --remove-all-files, their files remain on disk with numerical UID ownership (e.g., owned by UID 1001). You can find orphaned files using find / -nouser./etc/passwd filtering for standard interactive UIDs (typically between 1000 and 60000): awk -F: '($3 >= 1000 && $3 < 60000) {print $1}' /etc/passwd.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides


Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!