In this tutorial we will learn to delete user account in Linux.
In one of the previous tutorial we learned how to create a new user in linux using useradd command. Feel free to check that out.
Before we run the commands given in this tutorial we will switch to root user by running the sudo su command.
In the following example I am switching from my account to root account. You will get a similar result on your terminal.
yusufshakeel@yusufshakeel-ubuntu:~$ sudo su
[sudo] password for yusufshakeel:
Notice the $ sign changes to # and we also switch from yusufshakeel user account to root account.
Alright, lets learn how to delete user accounts.
We start the deletion process by first locking the user account so that the user can't login again.
In the following example we are locking jane account.
# passwd --lock jane
passwd: password expiry information changed.
Now we will kill all the processes by the user using the killall command.
In the following example we are listing all the processes by user jane.
# pgrep -u jane
To kill all the processes by user jane we will run the following command.
# killall -u jane
We have successfully stopped the user from logging in and we have also killed all the processes connected with the user.
Now, we will backup the data files of the user before deleting the account.
This is an optional step. If you think you are not going to need the data of the user then you can jump to the next step.
In the following example we are creating a backup copy of jane user account and saving it inside /user-account-backup directory.
# tar -zcvf /user-account-backup/jane-user-account-home-directory-backup.tar.gz /home/jane
To delete the user we will use the userdel command.
In the following example we are deleting user account of jane.
# userdel --remove jane
On Debian and its derivative system try using deluser command.
# deluser --remove-home jane
Have fun learning :-)
Copyright © 2014 - 2023 DYclassroom. All rights reserved.