userdel

Linux · Users and permissions · reference only

What it does

Deletes a user account from the system. With -r it also removes the home directory and the mail spool.

Syntax

userdel [opciones] usuario

Options and parameters

  • -r

    Also removes the user's home directory and mail spool.

  • -f

    Forces removal even if the user is logged in; use with care.

  • -R DIR

    Applies the changes inside the given root directory (chroot), useful for system images.

  • -Z

    Also removes the user's SELinux mapping.

  • -h

    Shows help and exits.

Usage examples

  • sudo userdel ana

    Deletes the ana account but keeps her /home/ana directory.

  • sudo userdel -r ana

    Deletes the account and its whole home directory.

  • getent passwd ana

    Checks the account is gone: it prints nothing if the deletion worked.

  • sudo userdel -f pruebas

    Forces the removal of an account even if it is in use.

Notes and common mistakes

  • Without -r the user's files stay on disk and keep an orphan UID.
  • A user with running processes cannot be deleted unless you use -f.
  • On Debian and Ubuntu, deluser is a friendlier alternative.

Related commands