{"id":12113,"date":"2019-03-22T10:37:31","date_gmt":"2019-03-22T10:37:31","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12113"},"modified":"2019-03-22T10:37:31","modified_gmt":"2019-03-22T10:37:31","slug":"how-to-delete-user-accounts-with-home-directory-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/how-to-delete-user-accounts-with-home-directory-in-linux\/","title":{"rendered":"How to Delete User Accounts with Home Directory in Linux"},"content":{"rendered":"<p>In this tutorial, I am going to take your through steps you can use to delete a user\u2019s account together with his\/her home directory on a Linux system.<\/p>\n<div id=\"attachment_17484\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Delete-User-Account-with-Home-Directory-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17484\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Delete-User-Account-with-Home-Directory-in-Linux.png\" alt=\"Delete User Accounts with Home Directory in Linux\" width=\"718\" height=\"341\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Delete User Accounts with Home Directory in Linux<\/p>\n<\/div>\n<p>To learn how to create user accounts and manage them on Linux systems, read the following articles from the links below:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/add-users-in-linux\/\" target=\"_blank\" rel=\"noopener\">15 \u201cuseradd\u201d Command Examples to Manage User Accounts in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/usermod-command-examples\/\" target=\"_blank\" rel=\"noopener\">15 \u201cusermod\u201d Command Examples to Change\/Modify User Account Names in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/manage-users-and-groups-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Manage Users &amp; Groups with File Permissions in Linux<\/a><\/li>\n<\/ol>\n<p>As a\u00a0<strong>System Administrator<\/strong>\u00a0in Linux, you may have to remove users account at after sometime when a user account may become dormant for so long, or user may leave the organization or company or any other reasons.<\/p>\n<p>When removing user accounts on a Linux system, it is also important to remove their home directory to free up space on the storage devices for new system users or other services.<\/p>\n<p><strong>1.<\/strong>\u00a0For demonstration purpose, first I will start by creating two user accounts on my system that is user\u00a0<strong>tecmint<\/strong>and user\u00a0<strong>linuxsay<\/strong>\u00a0with their home directories\u00a0<strong>\/home\/tecmint<\/strong>\u00a0and\u00a0<strong>\/home\/linusay<\/strong>\u00a0respectively using\u00a0<strong>adduser<\/strong>command.<\/p>\n<pre># adduser tecmint\r\n# passwd tecmint\r\n\r\n# adduser linuxsay\r\n# passwd linuxsay\r\n<\/pre>\n<div id=\"attachment_17473\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Create-New-User-Accounts-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17473\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Create-New-User-Accounts-in-Linux.png\" alt=\"Create New User Accounts in Linux\" width=\"684\" height=\"325\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create New User Accounts in Linux<\/p>\n<\/div>\n<p>From the screenshot above, I have used the\u00a0<strong>adduser<\/strong>\u00a0command to create user accounts on Linux. You can also use\u00a0<strong>useradd<\/strong>\u00a0command, both are same and does the same job.<\/p>\n<p><strong>2.<\/strong>\u00a0Let\u2019s now move further to see how to delete or remove user accounts in Linux using\u00a0<strong>deluser<\/strong>\u00a0(For Debian and it\u2019s derivatives) and\u00a0<strong>userdel<\/strong>\u00a0(For RedHat\/CentOS based systems) command.<\/p>\n<p>The directives inside the configuration file for\u00a0<strong>deluser<\/strong>\u00a0and\u00a0<strong>userdel<\/strong>\u00a0commands determine how this it will handle all user files and directory when you run the command.<\/p>\n<p>Let us look at the configuration file for the\u00a0<strong>deluser<\/strong>\u00a0command which is\u00a0<code>\/etc\/deluser.conf<\/code>\u00a0on Debian derivatives such as Ubuntu, Kali, Mint and for RHEL\/CentOS\/Fedora users, you can view the\u00a0<code>\/etc\/login.defs<\/code>files.<\/p>\n<p>The values in the these configuration are default and can be changed as per your needs.<\/p>\n<pre># vi \/etc\/deluser.conf         [On Debian and its derivatives]\r\n# vi \/etc\/login.defs           [On RedHat\/CentOS based systems]\r\n<\/pre>\n<p><strong>3.<\/strong>\u00a0To delete a user with home directory, you can use the advanced way by following these steps on your Linux server machine. When users are logged on to the server, they use services and run different processes. It is important to note that user can only be deleted effectively when they are not logged on to the server.<\/p>\n<h4>Lock User Accounts in Linux<\/h4>\n<p>Start by locking the user account password so that there is no access for the user to the system. This will prevent a user from running processes on the system.<\/p>\n<p>The\u00a0<strong>passwd<\/strong>\u00a0command including the\u00a0<strong>\u2013lock<\/strong>\u00a0option can help you achieve this:<\/p>\n<pre><strong># passwd --lock tecmint<\/strong>\r\n\r\nLocking password for user tecmint.\r\npasswd: Success\r\n<\/pre>\n<div id=\"attachment_17475\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Lock-User-Account-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17475\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Lock-User-Account-in-Linux.png\" alt=\"Lock User Account Password in Linux\" width=\"607\" height=\"135\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Lock User Account Password in Linux<\/p>\n<\/div>\n<h4>Find and Kill All Running Processes of User<\/h4>\n<p>Next find out all running processes of user account and kill them by determine the\u00a0<strong>PIDs<\/strong>\u00a0(<strong>Process IDs<\/strong>) of processes owned by the user using:<\/p>\n<pre><strong># pgrep -u tecmint<\/strong>\r\n\r\n1947\r\n1959\r\n2091\r\n2094\r\n2095\r\n2168\r\n2175\r\n2179\r\n2183\r\n2188\r\n2190\r\n2202\r\n2207\r\n2212\r\n2214\r\n<\/pre>\n<div class=\"google-auto-placed ap_container\">\n<p>Then you can list the processes interms of username, PIDs, PPIDs (Parent Process IDs), terminal used, process state, command path in a full formatting style with the help of following command as shown:<\/p>\n<pre><strong># ps -f --pid $(pgrep -u tecmint)<\/strong>\r\n\r\nUID        PID  PPID  C STIME TTY      STAT   TIME CMD\r\ntecmint   1947     1  0 10:49 ?        SLl    0:00 \/usr\/bin\/gnome-keyring-daemon --daemonize --login\r\ntecmint   1959  1280  0 10:49 ?        Ssl    0:00 mate-session\r\ntecmint   2091  1959  0 10:49 ?        Ss     0:00 \/usr\/bin\/ssh-agent \/usr\/bin\/dbus-launch --exit-with-session \/usr\/bin\/im-launch mate-session\r\ntecmint   2094     1  0 10:49 ?        S      0:00 \/usr\/bin\/dbus-launch --exit-with-session \/usr\/bin\/im-launch mate-session\r\ntecmint   2095     1  0 10:49 ?        Ss     0:00 \/\/bin\/dbus-daemon --fork --print-pid 6 --print-address 9 --session\r\ntecmint   2168     1  0 10:49 ?        Sl     0:00 \/usr\/lib\/dconf\/dconf-service\r\ntecmint   2175  1959  0 10:49 ?        Sl     0:02 \/usr\/bin\/mate-settings-daemon\r\ntecmint   2179  1959  0 10:49 ?        Sl     0:47 marco\r\ntecmint   2183     1  0 10:49 ?        Sl     0:00 \/usr\/lib\/gvfs\/gvfsd\r\ntecmint   2188  1959  0 10:49 ?        Sl     0:00 mate-panel\r\ntecmint   2190     1  0 10:49 ?        Sl     0:00 \/usr\/lib\/gvfs\/gvfsd-fuse \/run\/user\/1000\/gvfs -f -o big_writes\r\ntecmint   2202     1  0 10:49 ?        S&lt;l    0:20 \/usr\/bin\/pulseaudio --start --log-target=syslog\r\ntecmint   2207  1959  0 10:49 ?        S      0:00 \/bin\/sh \/usr\/bin\/startcaja\r\ntecmint   2212     1  0 10:49 ?        Sl     0:03 \/usr\/bin\/python \/usr\/lib\/linuxmint\/mintMenu\/mintMenu.py\r\ntecmint   2214     1  0 10:49 ?        Sl     0:11 \/usr\/lib\/mate-panel\/wnck-applet\r\n....\r\n<\/pre>\n<div id=\"attachment_17477\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Find-All-Running-Processes-of-User.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17477\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Find-All-Running-Processes-of-User.png\" alt=\"Find All Running Processes of User\" width=\"893\" height=\"458\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find All Running Processes of User<\/p>\n<\/div>\n<p>Once you find all the running processes of user, you can use the\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-kill-a-process-in-linux\/\" target=\"_blank\" rel=\"noopener\">killall command<\/a>\u00a0to kill those running processes as shown.<\/p>\n<pre># killall -9 -u tecmint\r\n<\/pre>\n<p>The\u00a0<strong>-9<\/strong>\u00a0is the signal number for the\u00a0<strong>SIGKILL<\/strong>\u00a0signal or use\u00a0<strong>-KILL<\/strong>\u00a0instead of\u00a0<strong>-9<\/strong>\u00a0and\u00a0<strong>-u<\/strong>\u00a0defines username.<\/p>\n<p><strong>Note<\/strong>: In recent releases of RedHat\/CentOS 7.x versions and Fedora 21+, you will get error message as:<\/p>\n<pre>-bash: killall: command not found\r\n<\/pre>\n<p>To fix such error, you need to install psmisc package as shown:<\/p>\n<pre># yum install psmisc       [On RedHat\/CentOS 7.x]\r\n# dnf install psmisc       [On Fedora 21+ versions]\r\n<\/pre>\n<h4>Backup User Data Before Deleting<\/h4>\n<p>Next you can backup users files, this can be optional but it is recommended for future use when need arises to review user account details and files.<\/p>\n<p>I have used the\u00a0<a href=\"https:\/\/www.tecmint.com\/18-tar-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">tar utilities<\/a>\u00a0to create a backup of users home directory as follows:<\/p>\n<pre># tar jcvf \/user-backups\/tecmint-home-directory-backup.tar.bz2 \/home\/tecmint\r\n<\/pre>\n<div id=\"attachment_17480\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Backup-User-Home-Directory-in-Linux.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17480\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Backup-User-Home-Directory-in-Linux.png\" alt=\"Backup User Home Directory in Linux\" width=\"937\" height=\"496\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Backup User Home Directory in Linux<\/p>\n<\/div>\n<h4>Delete\/Remove User Account and Files<\/h4>\n<p>Now you can safely remove user together with his\/her home directory, to remove all user files on the system use the\u00a0<code>--remove-all-files<\/code>\u00a0option in the command below:<\/p>\n<pre># deluser --remove-home tecmint      [On Debian and its derivatives]\r\n# userdel --remove tecmint           [On RedHat\/CentOS based systems]\r\n<\/pre>\n<div id=\"attachment_17481\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Delete-User-Account-and-Files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17481\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Delete-User-Account-and-Files.png\" alt=\"Delete User Account with Home Directory\" width=\"783\" height=\"344\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Delete User Account with Home Directory<\/p>\n<\/div>\n<h3>Summary<\/h3>\n<p>That is all to do with removing user and their home directory from a Linux system. I believe the guide is easy enough to follow, but you can voice a concern or add more idea by leaving a comment.<\/p>\n<p><a style=\"font-size: 1rem;\" href=\"https:\/\/www.tecmint.com\/delete-remove-a-user-account-with-home-directory-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I am going to take your through steps you can use to delete a user\u2019s account together with his\/her home directory on a Linux system. Delete User Accounts with Home Directory in Linux To learn how to create user accounts and manage them on Linux systems, read the following articles from the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/how-to-delete-user-accounts-with-home-directory-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Delete User Accounts with Home Directory in Linux&#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-12113","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\/12113","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=12113"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12113\/revisions"}],"predecessor-version":[{"id":12114,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12113\/revisions\/12114"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}