Linux delete user command

last updated in Categories , , , , ,

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

Linux delete user account command
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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at

Historical Comment Archive

3 comment

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

  2. 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?

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

    Still, have a question? Get help on our forum!