How to completely delete a user in Ubuntu

Original link: https://www.codewoody.com/posts/28965/

Deleting a user completely in Ubuntu involves several steps, not just deleting the user, but possibly also deleting data associated with the user. Here is the step by step guide:

  1. Make sure the user is not logged in : Before deleting a user, it is best to make sure that the user is not logged in. You can use the who command to check which users are currently logged in.

     1
     who
  2. Delete user : Use the userdel command to delete a user. If you also wish to delete the user’s home directory and mail pool, use -r option.

     1
     sudo userdel -r username

    where username is the username of the user you want to delete.

    Note: -r option deletes the user’s home directory (usually /home/username ). Make sure you have backed up all important data!

  3. Check the file system : Even after deleting a user and their home directory, there may still be some files left on the file system belonging to that user. You can use the find command to search for these files:

     1
     sudo find / -user username

    This will list all files belonging to username . Depending on your needs, you can manually delete these files or change their ownership.

  4. Delete user’s cron jobs : If the user has any cron jobs configured, you will also need to delete them manually. Check if /var/spool/cron/crontabs/username exists, and delete it if it exists.

     1
     sudo rm /var/spool/cron/crontabs/username
  5. Other services or configuration : If the user has other specific configurations, such as entries in /etc/sudoers or special access rights in other services, you need to manually check and remove them.

Please make sure to backup any important data before proceeding with any deletion. Make sure you know exactly what you’re doing to avoid accidentally deleting important files or configurations.

This article is transferred from: https://www.codewoody.com/posts/28965/
This site is only for collection, and the copyright belongs to the original author.