How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Add and Delete Users on a Linux Server from the Terminal
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Server Management > How to Add and Delete Users on a Linux Server from the Terminal
Server Management

How to Add and Delete Users on a Linux Server from the Terminal

how7o
By how7o
Last updated: May 22, 2026
7 Min Read
Linux add and delete users from the terminal — adduser, passwd, sudo group, userdel
SHARE

To add and delete users on a Linux server from the terminal, you have four commands: adduser to create, passwd to set the password, usermod -aG to grant sudo, and userdel -r to delete with their home directory. This guide walks through the full lifecycle on any modern Linux (AlmaLinux, Rocky, RHEL, Debian, Ubuntu).

Contents
  • TL;DR
  • Add a user
  • Grant sudo privileges
  • Set or change a password
  • Delete a user
  • Useful related commands
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 on AlmaLinux 9 and Ubuntu 22.04. Originally published 2023-01-09, rewritten and updated 2026-05-17.

TL;DR

# Create the user (interactive — prompts for password, gecos, etc.)
sudo adduser jonny

# Or, scripted equivalent
sudo useradd -m -s /bin/bash jonny
echo 'jonny:initialpass' | sudo chpasswd

# Grant sudo (RHEL family)
sudo usermod -aG wheel jonny

# Grant sudo (Debian/Ubuntu)
sudo usermod -aG sudo jonny

# Delete user and their home directory
sudo userdel -r jonny

Add a user

sudo adduser jonny

On Debian/Ubuntu, adduser is a friendly interactive wrapper — it prompts for a password, full name, room number (which you can leave blank), and confirms. It creates the home directory at /home/jonny, copies skeleton files from /etc/skel/, sets the default shell, and creates a primary group named after the user.

On RHEL/AlmaLinux/Rocky, adduser is a symlink to useradd — non-interactive. Use this scripted form instead:

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

-m creates the home directory; -s /bin/bash sets the login shell. passwd prompts for the new password twice.

Linux add and delete users from terminal — adduser, passwd, usermod -aG, userdel -r

Grant sudo privileges

By default, the new user can log in and do whatever their own files allow — but can’t sudo. The fix is to add them to the admin group. Which group depends on the distro:

# RHEL / AlmaLinux / Rocky / Fedora — group is "wheel"
sudo usermod -aG wheel jonny

# Debian / Ubuntu — group is "sudo"
sudo usermod -aG sudo jonny

-aG is critical: -a appends (without it, you’d replace the user’s group list, removing them from every other group); -G sets supplementary groups. Verify with id jonny — the wheel/sudo group should appear in the output.

The new sudo access takes effect on the user’s next login. Have them exit and SSH back in, then test:

sudo whoami     # Should print: root

Set or change a password

# Interactive — prompts twice
sudo passwd jonny

# The user can also change their own
passwd

For automation (cloud-init, provisioning scripts):

# Debian/Ubuntu — chpasswd reads user:pass pairs from stdin
echo 'jonny:newpass' | sudo chpasswd

# RHEL family — passwd --stdin
echo 'newpass' | sudo passwd --stdin jonny

Delete a user

# Remove user, keep their home directory
sudo userdel jonny

# Remove user AND their home directory and mail spool
sudo userdel -r jonny

The -r flag is what you usually want when offboarding — otherwise /home/jonny persists on disk indefinitely.

If userdel errors with user is currently used by process X, the account still has an active session or daemon. Find it with pgrep -u jonny, then either wait for the session to end or kill the processes: sudo pkill -KILL -u jonny.

Useful related commands

# What groups does a user belong to?
id jonny
groups jonny

# Lock / unlock without deleting
sudo usermod -L jonny     # lock
sudo usermod -U jonny     # unlock

# Force password change on next login
sudo chage -d 0 jonny

# List human (non-system) users
awk -F: '$3 >= 1000 {print $1}' /etc/passwd

Frequently asked questions

What’s the difference between adduser and useradd?

useradd is the low-level binary that creates the user entry in /etc/passwd — it doesn’t prompt for a password, doesn’t create a home directory unless you pass -m, doesn’t set the shell beyond the default. adduser is an interactive wrapper (Perl on Debian/Ubuntu, sometimes a shell script on RHEL) that prompts for everything and sets sensible defaults. For interactive setup, use adduser. For scripted/automated setup, use useradd with explicit flags.

What’s the wheel group, and why does my user need it for sudo?

wheel is the traditional Unix admin group — members are granted sudo access via a line in /etc/sudoers (or a drop-in under /etc/sudoers.d/). On RHEL/AlmaLinux/Rocky, the group is wheel. On Debian/Ubuntu, it’s sudo. Add a user to the right group with usermod -aG wheel jonny (RHEL) or usermod -aG sudo jonny (Debian/Ubuntu).

How do I delete a user along with all their files?

sudo userdel -r jonny on every modern Linux. The -r flag tells userdel to remove the home directory and mail spool too. Without it, the account is removed but /home/jonny stays on disk — useful when you want to preserve work, but easy to forget about cleanup later.

How do I list all non-system users?

awk -F: '$3 >= 1000 {print $1}' /etc/passwd prints every user with UID 1000 or higher — the convention for human accounts. System accounts (root, daemon, sshd, etc.) live below 1000 (or below 500 on very old systems).

Can I change a user’s password without prompts (for automation)?

Yes — echo 'newpass' | sudo passwd --stdin jonny works on RHEL family. On Debian/Ubuntu, use chpasswd: echo 'jonny:newpass' | sudo chpasswd. Both are non-interactive and suitable for cloud-init or provisioning scripts. Treat the password string carefully — it’ll show up in shell history.

Related guides

  • How to Add a User to Pure-FTPd from the Command Line on Linux
  • How to Enable CageFS for a User on CloudLinux
  • How to List Network Devices on Linux

References

man adduser, man useradd, man userdel, man usermod on any Linux system. RHEL documentation on user/group management: access.redhat.com — managing local users and groups.

TAGGED:BashconfigurationSecuritySSH

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Enable CageFS for a user on CloudLinux — cagefsctl CLI and CloudLinux Manager How to Enable CageFS for a User on CloudLinux / cPanel
Next Article jQuery add required attribute to input fields — .prop() method How to Add the Required Attribute to Input Fields with jQuery
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Configure Nginx for WordPress in aaPanel (fix 404 permalinks)
Server Management

Configure Nginx for WordPress in aaPanel (Fix Permalink 404 Errors)

5 Min Read
Fix broken cPanel disk quotas with the fixquotas script
Server Management

How to Fix Quotas in cPanel

5 Min Read
Check Ubuntu version — terminal and Settings
Server Management

How to Check Your Ubuntu Version

4 Min Read
Migrating files from cPanel to aaPanel using rsync
Server Management

cPanel to aaPanel Migration with rsync: Fix Permissions, SSH Port, and CSF Firewall

6 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?