How to Disable or Completely Delete Linux Server Users

Disabling a user account can be very useful if the account has been compromised, the user has left but may return in the future, or for punitive purposes. To disable a user on a Linux system, you can use the following command string:

# usermod –lock –expiredate 1970-01-01 <username>

Replace <username> with the actual user’s login name, and the expiration date can be any date before the current date.

Completely Remove a User

When you part ways with a user, there is a chance you might forget to remove that user from your server. Once you decide the user is never coming back, you definitely should remove the user completely. Use this command string to delete a user:

# userdel username

You may also want to delete the files stored in the user’s home directory. Using the “-r” option, you can delete the user’s home directory and mail spool completely.

# userdel -r username

Once the user has been deleted, that user will no longer be able to log in, view, or modify any of the files he/she once had access to on your server.