How to Delete a User in Linux

User accounts on a Linux system that are no longer being used should be removed. This is better for security, and you don’t want your computer or server convoluted with unused accounts.

In this guide, we’ll go over the step by step instructions to delete a user via Linux command line.

Note: It’s also possible to simply disable a user on Linux if you don’t wish to delete the account completely.

Remove a User in Linux

The userdel command is used to delete a user account in Linux. Simply specify the name of the user after your command. Note that this will require root privileges.

$ sudo userdel james

To remove the user’s home directory at the same time, add the -r option to your command.

$ sudo userdel -r james

Use the -f option to force remove the files in the home directory, even if they’re not owned by the user.

$ sudo userdel -r -f james

Used by Process Error Message

The userdel command won’t work if there are processes running under the account. You will receive an error like the one below.

userdel: user james is currently used by process 20160

If you receive this message, you can use the kill command to terminate all the processes running under the user.

$ killall -u james

Stubborn processes can be forcefully closed with the -9 option.

$ killall -9 -u james

Alternatively, use the -f option to force user deletion. This is a last resort and should be used sparingly.

$ userdel -f james

If our content helped you, please consider buying us a coffee. We appreciate your support!

Buy me a coffee donation button

Leave a Comment

Your email address will not be published. Required fields are marked *