Back to course

42. Managing Users: Deleting Accounts (`userdel`)

Linux Basics: From Zero to CLI Hero

Account Removal

Use the userdel command to remove a user account from the system.

Basic Deletion

This removes the user's entry from system files like /etc/passwd but leaves their home directory and mailbox intact.

bash $ sudo userdel jdoe

Deleting Home Directory and Mail Spool (-r)

To completely clean up the user's data, use the -r (remove files) option.

bash

Deletes the user and their /home/jdoe directory

$ sudo userdel -r jdoe

Important: If the user is currently logged in or has active processes, deletion might fail or cause system instability. Always ensure the user is logged out before deletion.