{"id":343,"date":"2018-10-17T09:32:32","date_gmt":"2018-10-17T09:32:32","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-delete-a-user-on-ubuntu\/"},"modified":"2018-10-17T09:32:32","modified_gmt":"2018-10-17T09:32:32","slug":"how-to-delete-a-user-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-delete-a-user-on-ubuntu\/","title":{"rendered":"How to Delete a User on Ubuntu"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"delete user and home directory ubuntu\" height=\"341\" src=\"https:\/\/linoxide.com\/wp-content\/uploads\/2018\/09\/delete-user-and-home-directory-Ubuntu.png\" width=\"713\" \/><\/p>\n<p>How do I delete a user from your Ubuntu Linux system? Such instances include when users leave the company or when their accounts become dormant for so long. In this tutorial, I will show you how to delete a user and home directory on Ubuntu 18.04.<\/p>\n<p>But first, we are going to carry out some pre-tasks before deleting the user and home directory. These tasks will include<\/p>\n<p>1) Locking the User account<\/p>\n<p>2) Killing any processes associated with the user3) Backing up the user&#8217;s home directory4) Removing any cron\/print jobs5) Deleting\/removing user accounts<\/p>\n<\/p>\n<h2>1) Lock the User account<\/h2>\n<p>Begin by first locking the user&#8217;s account to deny them entry into the system. The syntax for this will be<\/p>\n<p>passwd -l <\/p>\n<p>For example<\/p>\n<p>passwd -l alice<\/p>\n<p>Output<\/p>\n<p>Locking password for user alice.&#xD;<br \/>\npasswd: Success<\/p>\n<h2>2) Kill all running processes of the User<\/h2>\n<p>After successfully locking the account, you need to find all the running processes attached to the user account and &#8216;kill&#8217; them using their PID (Process IDs)<br \/>\nUsing the ps command, the syntax is<\/p>\n<p>ps -u <\/p>\n<p>For example<\/p>\n<p>ps -u alice<\/p>\n<p>Output<\/p>\n<p> PID TTY TIME CMD&#xD;<br \/>\n 6561 pts\/0 00:00:00 bash&#xD;<br \/>\n 6586 pts\/0 00:00:00 ps&#xD;<\/p>\n<p>Using the top command, the syntax will be<\/p>\n<p>top -U <\/p>\n<p>For instance<\/p>\n<p>top -U alice<\/p>\n<p>Output<\/p>\n<p> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND&#xD;<br \/>\n 6561 alice 20 0 21196 5000 3224 S 0.0 0.5 0:00.03 bash&#xD;<br \/>\n 6595 alice 20 0 40540 3748 3148 R 0.0 0.4 0:00.01 top&#xD;<\/p>\n<p>To end or &#8216;kill&#8217; all the running processes, use the killall command as shown<\/p>\n<p>killall -9 -u <\/p>\n<p>In our case, we shall have<\/p>\n<p>killall -9 -u alice&#xD;<\/p>\n<p>-9 flag is the SIGKILL command. It tells the system to terminate the processes without cleaning up.<br \/>-u flag defines the username<\/p>\n<h2>3) Backup user data before deleting<\/h2>\n<p>This is an optional step, but highly recommended should a need for reviewing a user&#8217;s account or files arise.<br \/>\nI decided to use tar utility to perform the backup. The syntax would be<\/p>\n<p>tar cvjf backup.tar.bz \/home\/username<\/p>\n<p>In our example, the syntax will be<\/p>\n<p>tar cvjf backup.tar.bz \/home\/alice<\/p>\n<p>Sample Output<\/p>\n<p>tar: Removing leading `\/&#8217; from member names&#xD;<br \/>\n\/home\/alice\/&#xD;<br \/>\n\/home\/alice\/.bash_history&#xD;<br \/>\n\/home\/alice\/.profile&#xD;<br \/>\n\/home\/alice\/.bashrc&#xD;<br \/>\n\/home\/alice\/.bash_logout&#xD;<\/p>\n<h2>4) Delete the user&#8217;s cron jobs<\/h2>\n<p>To delete the cron jobs of a user, run<\/p>\n<p>crontab -r -u alice<\/p>\n<p>To erase printer jobs run<\/p>\n<p>lprm alice<\/p>\n<h2>5) Delete\/ remove user account and files<\/h2>\n<p>We&#8217;ve finally reached the last stage of removing or erasing user accounts from the system. The above command will remove both the user account and the home directory.<\/p>\n<p>userdel -r alice<\/p>\n<p>In this case, the user &#8216;Alice&#8217; alongside the home directory will be purged. This is because we have used the -r flag.<\/p>\n<p>To delete the user only and retain the home directory, simply run<\/p>\n<p>userdel alice<\/p>\n<p>In this tutorial, we have briefly outlined the steps you need to take to delete a user and home directory from your system in a step-by-step manner. We hope you have taken note in case next time you are faced with such a scenario.<\/p>\n<h3>Read Also:<\/h3>\n<ul>\n<li><a href=\"https:\/\/linoxide.com\/linux-how-to\/linux-kill-command-examples\/\" target=\"_blank\">How to Stop Process Using Kill Command in Linux<\/a><\/li>\n<li><a href=\"https:\/\/linoxide.com\/linux-command\/linux-list-group-members-in-linux-terminal\/\" target=\"_blank\">Linux List Group Members in Linux Terminal<\/a><\/li>\n<\/ul>\n<p> <a href=\"https:\/\/linoxide.com\/linux-command\/how-delete-remove-user-ubuntu\/\" target=\"_blank\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How do I delete a user from your Ubuntu Linux system? Such instances include when users leave the company or when their accounts become dormant for so long. In this tutorial, I will show you how to delete a user and home directory on Ubuntu 18.04. But first, we are going to carry out some &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-delete-a-user-on-ubuntu\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Delete a User on Ubuntu&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-343","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=343"}],"version-history":[{"count":0,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/343\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}