Linux delete user command

I am a new Linux sysadmin. How do I remove a user account named foo? How can I delete user using the command line option?

Do you want to remove a user account from the Linux based system? Use the userdel command on the command line. This page shows how to delete users on Linux.

Linux delete user command

As root user type command
userdel {username}
sudo userdel {username}
userdel [option] {username}

How to list users on Linux system

Use the cat command or more command to view /etc/passwd file:
$ cat /etc/passwd
$ more /etc/passwd

How to search for given username

Use the following grep command to locate a particular user name:
$ grep "^username" /etc/passwd
$ grep "^raj" /etc/passwd

Deleting user account named raj

Say you want to delete user named raj, run:
$ sudo userdel raj
# userdel raj
Verify that user account deleted from the Linux:
$ grep "^raj" /etc/passwd

Deleting user account named raj using userdel command on Linux

Linux remove user account command

One can combine usedel command with the -r option. The -r option removes user’s home directory along with all files and email. The syntax is:
userdel -r {username}
sudo userdel -r {username}

For example remove user named tristan and delete the user’s home directory too:
$ sudo userdel -r tristan
# userdel -r tristan
Make sure user account delete on Linux. Run id command or grep command for verification:
$ id tristan
$ grep "^tristan" /etc/passwd
$ sudo ls /home/tristan/

How to remove any SELinux user mapping for the user’s login

sudo userdel -Z -r {username}
sudo userdel -Z -r vivek

How to forcefully delete user account when is currently logged in to Linux server

Pass the -f option to the userdel command. It forces the removal of the user account, even if the user is still logged in. For example:
$ sudo userdel -r rob
[sudo] password for vivek:
userdel: user rob is currently used by process 4650

To get rid of “userdel: user rob is currently used by process 4650“, run:
$ sudo userdel -r -f rob


Use userdel command to delete a user account and related files on Linux.

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

🐧 3 comments 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
3 comments… add one
  • Dr. DJ Mar 14, 2012 @ 18:17

    I search in Yahoo for “How do i deactivate Linux user account?” and this page help me. Thanks admin!

  • Aditya May 14, 2013 @ 11:14

    Yes, the -r option is pretty safer, and thus recommended. Now I do not recommend the -f option which forces the removal of the user account even if the user is still logged in. You really don’t want that, do you?

  • Badshah Oct 2, 2014 @ 1:02

    I wanna delete user accounts with home directory in Linux. I try and it worked as told here:
    su -
    userdel -r username
    id username

Leave a Reply

Your email address will not be published.

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