A common system administration task that you may need to perform on a Linux server is removing a user account. It is very easy to remove a user. The steps below will quickly outline the commands and procedures to do so. Removing old and inactive user accounts is an important security process as it reduces the potential attack surface.
- Access the server via SSH.
- Switch to root:
sudo su -
- The userdel command safely deletes the specified user:
- You may also delete the user’s home directory and mail spool with the optional -r flag.
userdel -r <username>
Warning: This command cannot be undone so only delete a user’s home directory if you no longer need access to their files or mail.