On Unix-like operating systems, the userdel command deletes a user account and all associated files.

This page covers the Linux version of userdel.

Description

userdel is a low-level utility for removing users. (It is not very user-friendly. In most cases, administrators are advised to use the friendlier deluser utility instead.)

  • Description
  • Syntax
  • Configuration
  • Files
  • Exit status
  • Notes
  • Examples
  • Related commands
  • Linux commands help

The userdel command modifies the system account files, deleting all entries that refer to the username LOGIN. The named user must exist.

Syntax

userdel [options] LOGIN

Options

Configuration

The following configuration variables in /etc/login.defs change the behavior of this tool:

Note that the MAIL_DIR and MAIL_FILE variables are used by each of useradd, usermod, and userdel to create, move, or delete the user’s mail spool.

#! /bin/sh# Check for the required argument.if [ $# != 1 ]; then echo “Usage: $0 username” exit 1fi# Remove cron jobs.crontab -r -u $1# Remove at jobs.# Note that it removes any jobs owned by the sam shared by a different username.AT_SPOOL_DIR=/var/spool/cron/atjobsfind $AT_SPOOL_DIRe UID,# even if it was -name “[^.]*” -type f -user $1 -delete ;# Remove print jobs.lprm $1# All done.exit 0

Files

Exit status

userdel exits with one of the following exit codes, depending on what occurred:

Notes

userdel prevents you from removing an account if there are running processes which belong to this account. In that case, you may have to kill those processes or lock the user’s password or account and remove the account later. The -f option can force the deletion of this account.

You should manually check all file systems to ensure that no files remain owned by this user.

You may not remove any NIS attributes on a NIS client. This must be performed on the NIS server.

If USERGROUPS_ENAB is defined to “yes” in /etc/login.defs, userdel deletes the group with the same name as the user. To avoid inconsistencies in the passwd and group databases, userdel checks that this group is not used as a primary group for another user, and warns without deleting the group otherwise. The -f option can force the deletion of this group.

Examples

userdel -r username

Deletes the account of user username, and removes that user’s home directory and associated mail files.

useradd — Add a user to the system.usermod — Modify a user’s account.