Commands

Beginner’s Guide To Delete Or Remove A User On Ubuntu

Delete Or Remove A User On Ubuntu

In this tutorial, we are going to show you the methods to delete or remove a user on Ubuntu operating system. Meanwhile, commands used below is applicable to the most of the Linux based operating system.

Beginner’s Guide To Delete Or Remove A User On Ubuntu

Before removing the user or deleting the user from the system, we need to make sure that they are not doing any tasks when we are performing the deletion or removal process. So, we need to the lock the user account.

Run the following command in your terminal to lock the user account:

passwd -l {username}

For example:

passwd -l omgfoss

Output

Locking password for user omgfoss.
passwd: Success

After locking the user account, you need to make sure that the all processes attached to this account is stopped or killed.

After successfully locking the account, you need to kill the running processes attached to the user account.
You need to the run the following command to kill the running processes of the user account:

At first we need to know the process id:

ps -u {username}

To end or ‘kill’ all the running processes:

killall -9 -u {username}

Now, Delete the cron job of the user:

crontab -r -u alice

For printer jobs:

lprm alice

Finally, It’s time to remove the user account and the respective files from the system. The following command will also remove the home directory of the user from the system.

 

userdel -r omgfoss

To delete the user but not the home directory, Run the following command:

userdel omgfoss

This is for now. In this tutorial, we tried to make everything simple and easy to understand for our users who are at the initial phase of learning Linux/Ubuntu. Let us know if there is anything missing or wrong in this article.

READ THIS ALSO  Apt-Clone To Backup Installed Packages And Restore On Linux

If you find this tutorial post useful then don’t forget to share it 😉

 



Subscribe To Our Newsletter.

Join our mailing list to receive the latest linux tutorials, tips & tricks, freebies,news and updates from our team.

You have Successfully Subscribed!