Userdel

From Unix SME

NAME

      userdel - delete a user account and related files

SYNOPSIS

      userdel [options] LOGIN

DESCRIPTION

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

OPTIONS

      The options which apply to the userdel command are:
    1) -f, --force
          This option forces the removal of the user account, even if
          the user is still logged in. It also forces userdel to remove
          the user's home directory and mail spool, even if another
          user uses the same home directory or if the mail spool is not
          owned by the specified user. If USERGROUPS_ENAB is defined to
          yes in /etc/login.defs and if a group exists with the same
          name as the deleted user, then this group will be removed,
          even if it is still the primary group of another user.
          Note: This option is dangerous and may leave your system in
          an inconsistent state.
    2) -h, --help
          Display help message and exit.
    3) -r, --remove
          Files in the user's home directory will be removed along with
          the home directory itself and the user's mail spool. Files
          located in other file systems will have to be searched for
          and deleted manually.
          The mail spool is defined by the MAIL_DIR variable in the
          login.defs file.
    4) -R, --root CHROOT_DIR
          Apply changes in the CHROOT_DIR directory and use the
          configuration files from the CHROOT_DIR directory. Only
          absolute paths are supported.
    5) -P, --prefix PREFIX_DIR
          Apply changes in the PREFIX_DIR directory and use the
          configuration files from the PREFIX_DIR directory. This
          option does not chroot and is intended for preparing a
          cross-compilation target. Some limitations: NIS and LDAP
          users/groups are not verified. PAM authentication is using
          the host files. No SELINUX support.
    6) -Z, --selinux-user
          Remove any SELinux user mapping for the user's login.

EXAMPLES:

    1) Userdel --> [student@workstation ~]$ sudo userdel [username]

    2) Userdel -f --> [student@workstation ~]$ sudo userdel -f newuser
    3) Userdel -r --> [student@workstation ~]$ sudo userdel -r newuser2
    4) Userdel -h --> [student@workstation ~]$ userdel -h
    5) Userdel -R --> [student@workstation ~]$ sudo userdel -R newuser2
    6) Userdel -Z --> [student@workstation ~]$ sudo userdel -Z newuser2

References :

 https://man7.org/linux/man-pages/man8/userdel.8.html
 https://www.geeksforgeeks.org/userdel-command-in-linux-with-examples/#how-to-delete-user-in-linux-using-userdel-command