How to remove a user in Ubuntu?
To delete a user on Ubuntu, you can follow these steps:
- Open the terminal.
- By logging in with root privileges, you can use the following command to switch to the root user:
- Switch to superuser/root using the “su” command in Linux.
- Confirm that the user you want to delete does not have any open sessions. You can use the following command to list the currently logged in users and their sessions:
- whoever
- Delete the user using the following command:
- Delete the user along with their home directory: userdel -r username
- The username to be deleted is specified. The -r option will remove the user’s home directory.
- After removing the user, you can use the following command to confirm that the user has been deleted:
- Retrieve the user information by searching for the username in the /etc/passwd file.
- If the user information cannot be found, it means the user has been successfully deleted.
Please be aware that deleting a user is a sensitive operation, so please proceed with caution. Make sure you truly want to delete the user and backup any important user data.