How to Delete Users from Your Server

Part of the regular housekeeping of a dedicated server is cleaning out remnants of past users.  The last thing you want is for former users (especially former employees) to continue to log onto your server.  This is especially dangerous if you had given them SSH access.

The solution is to delete users as soon as they are no longer welcome on your server.  If, for some reason, you forget or something goes wrong with your control panel or other automated user deletion, you can still manually remove users from the command line.

To delete a user, you just need to follow this simple formula:

userdel username

For example, to delete a user named ally, you would enter as root:

userdel ally

This, however, will leave the user’s home directory, which may contain files or scripts you no longer need or want on your system.  To remove the home directory and mail spool as well, add the “-r” option.

userdel -r ally

You may want to backup the contents of a user’s home directory and their mail spool before you delete them.  After all, a user may decide to return or may want that information.  If so, you can place it in a gzipped archive and send it to them.

For a complete example of a user deletion, from locking the account and backing up the files to the final removal, see this post.