Deleting users

When you have a user account that you no longer need, you might want to delete the old account. You have a couple of methods to delete that old account, and the choice of which method to use depends on your own situation.

Delete an existing user

  1. Log in to your system as the root user:

    localhost$ ssh root@<remote_ip>
  2. You can delete the user, but keep the user's files. To do so, run the following command, as root:

    # userdel olduser
  3. You can delete the user, and the user's files (home directory). To do so, run the following command, as root:

    # userdel -r olduser

If you are executing the commands using a non-root user with sudo privileges, remember to type sudo ahead of the command:

$ sudo userdel -r olduser

Using these commands, the user will be removed automatically from all the groups that it was added to, including the wheel group if it was given sudo privileges. If you need to add another user with the same name, at a later time, it will have to be added to the wheel group again to gain sudo privileges.


Other articles:

How to list all users in Linux - part 1

How to create users in Linux

How to create user groups in Linux

How to delete user groups in Linux