How to delete a user account on Ubuntu Linux

My AWS server has a user named ubuntu. I created another user for admin purpose. I no longer need a user account named ubuntu on Ubuntu Linux 18.04 LTS cloud server. How do I delete that user account?

Introduction: It is always a good idea to delete unwanted or unused user accounts on Ubuntu Linux or any other operating system for security reasons. This page shows how to remove a user account on Ubuntu Linux. You must log in as root delete a user from the Ubuntu Linux server.

How to delete a user account on Ubuntu

  1. Open the terminal app
  2. Login to server using the ssh user@server-ip-here command
  3. Run sudo deluser --remove-home userNameHere command to delete a user account on Ubuntu
  4. Verify it by running id command

Let us see all commands in details to remove a user account in Ubuntu.

Ubuntu delete user account command

Say you would like to delete a user named ubuntu, run:
$ sudo deluser --remove-home ubuntu
If you want to backup files before removing user account, try:
## create a dir to store backups ##
$ sudo mkdir /oldusers-data
$ sudo chown root:root /oldusers-data
$ sudo chmod 0700 /oldusers-data
$ sudo deluser --remove-home --backup-to /oldusers-data/ ubuntu

How to verify that user has been deleted from Ubuntu

Use the id command or grep command as follows:
$ id ubuntu
$ grep '^ubuntu' /etc/passwd

Deleting a user account in Ubuntu Linux

A note about /etc/deluser.conf file

The file /etc/deluser.conf contains defaults for the programs deluser and delgroup. You can edit this file to setup defaults. For example, you can set to remove the home directory and mail spool of the user to be removed by setting REMOVE_HOME to 1:

# Remove home directory and mail spool when user is removed

Use the cat command to display contains of /etc/deluser.conf:
$ cat /etc/deluser.conf
Sample outputs:

# /etc/deluser.conf: `deluser' configuration.
# Remove home directory and mail spool when user is removed
# Remove all files on the system owned by the user to be removed
# Backup files before removing them. This options has only an effect if
# target directory for the backup file
# delete a group even there are still users in this group
# exclude these filesystem types when searching for files of a user to backup
EXCLUDE_FSTYPES = "(proc|sysfs|usbfs|devpts|tmpfs|afs)"

How to remove a user account on Ubuntu Linux using userdel command

The syntax is:
$ sudo userdel -r {userName}
## remove tom user
$ sudo userdel -r tom

How to temporarily disable user login instead of deleting a user account

Use usermod command as follows:
$ sudo usermod -L -e 1 {username}
$ sudo usermod -L -e 1 jerry

You can specify expiry date too:
$ sudo usermod -e {YYYY-MM-DD} {username}
$ sudo usermod -e 2018-02-24 jerry

See “Linux Disable a User Account Command” for more info.

How to see log of deleted users on Ubuntu

You need to query /var/log/auth.log using either grep command or egrep command or cat command/tail command:
$ sudo tail -f /var/log/auth.log
$ sudo grep 'userdel' /var/log/auth.log
$ sudo grep 'ubuntu' /var/log/auth.log

Removing a user account and see log of deleted user account on Ubuntu with grep


You learned about deleting a user account on Ubuntu Linux when you no longer need them. I strongly suggest that you read man pages of deluser, userdel and deluser.conf by typing the following man command:
$ man userdel
$ man 5 deluser.conf

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Rani Dec 21, 2017 @ 20:14


    I just wanted to remove user john from group sudo, I execute:
    deluser rani sudo
    Now rani can’t use command like:
    sudo -i
    sudo systemctl restart ngnix

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @