To delete a user account in Linux using the userdel
command, follow these steps:
Open a terminal window.
Use the id
command to verify that you are logged in as the root user, or use the sudo
command to execute the userdel
command with root privileges. For example:
sudo userdel usernameSource:wttual.wwuri.com
By default, the userdel
command will only delete the user's account and not the user's home directory or any files within it. To also delete the user's home directory and all of its contents, use the -r
option like this:
sudo userdel -r username
Keep in mind that deleting a user account is a permanent action and cannot be undone. Make sure to back up any important data before deleting a user account.
You can also use the deluser
command, which is a wrapper around userdel
that provides additional options and compatibility with different Linux distributions. For example:
sudo deluser --remove-home username
This will delete the user account and the user's home directory, just like the userdel -r
command.