How to remove user accounts with home directory in Linux

Remove user accounts with home directory in Linux

In this article we will discuss how to remove user accounts with home directory in Linux. You can create user account and assign passwd for user at home directory.

To creating user and assigning passwd for user at home directory

We are going to create two users for example

[root@linuxhelp~]# useradd user4
[root@linuxhelp~]# useradd user5

< ads>


Example

[root@linuxhelp~]# passwd user5
Changing password for user user5.
New password: 
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.

To delete user accounts

Syntax
deluser [In Ubuntu based systems]
userdel [In CentOS based systems]

Example

vi /etc/deluser.conf        [On Debian/Ubuntu and its derivatives]
vi /etc/login.defs             [On RedHat/CentOS based systems]

5userdel-conf-file

6userdelconf-file2

To lock user accounts

This command is used to protect the system from other users.

Example

[root@linuxhelp~]# passwd --lock user5
Locking password for user user5. 
passwd: Success 
[root@linuxhelp~]# passwd --unlock user5
unLocking password for user user5. 
passwd: Success 

To kill running process of user

It can be killed by finding out the PIDs.

To grep any running process

Example

[root@linuxhelp~]# pgrep -u user5
1947
1959
2091
2094
2095
2168
2175

[root@linuxhelp~]# ps aux | grep user5
user5     2508  0.0  0.1 150532  1944 ?        Sl   11:34   0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
user5     2517  0.0  0.3 252660  3424 ?        Ssl  11:34   0:00 gnome-session
user5     2525  0.0  0.0  20036   320 ?        S    11:34   0:00 dbus-launch --sh-syntax --exit-with-session
user5     2526  0.0  0.1  22064  1252 ?        Ss   11:34   0:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
user5     2599  0.0  0.4 133404  4544 ?        S    11:34   0:01 /usr/libexec/gconfd-2
user5     2607  0.0  0.4 505396  4240 ?        Ssl  11:34   0:02 /usr/libexec/gnome-settings-daemon
.
.
.
.
user5     8702  0.0  0.1 108336  1784 pts/3    Ss   15:09   0:00 /bin/bash
root     10539  0.0  0.0 103248   840 pts/3    S+   16:42   0:00 grep user5

To kill a process

Syntax
Kill -9 “ process ID”

To take backup of user data

Syntax
tar -jcvf mybackup/user5.tar.bz2 /home/user5

Example

[root@linuxhelp~]# tar  -jcvf mybackup/user5.tar.bz2 /home/user5
/home/user1/
/home/user1/.pulse/
/home/user1/.pulse/a440afd05cdb59bd3135a9d100000013-default-source
/home/user1/.pulse/a440afd05cdb59bd3135a9d100000013-device-volumes.tdb
/home/user1/.pulse/a440afd05cdb59bd3135a9d100000013-default-sink
/home/user1/.pulse/a440afd05cdb59bd3135a9d100000013-card-database.tdb
/home/user1/.pulse/a440afd05cdb59bd3135a9d100000013-stream-volumes.tdb
/home/user1/.pulse/a440afd05cdb59bd3135a9d100000013-runtime
/home/user1/tar_linuxhelp.odt
/home/user1/.thumbnails/
/home/user1/.thumbnails/normal/
/home/user1/.thumbnails/normal/6a5d83a47302159097f5afb93347fd9b.png
/home/user1/.thumbnails/normal/202ad313ecb8799c0e78c3ff8b27f46b.png
/home/user1/.thumbnails/normal/cc046f2d93f68eabfa97c4d28c88cf13.png
.
.
.
/home/user1/.libreoffice/3/user/config/standard.soc
/home/user1/.libreoffice/3/user/config/standard.soh

To remove user account files

Syntax
deluser --remove-home username [On Debian/Ubuntu and its derivatives]

userdel --remove username [On RedHat/CentOS based systems]

Example:

[root@linuxhelp~]#userdel &ndash remove user5
[root@linuxhelp~]#ls -l /home 
drwx------.  4 c     c     4096 Jan 28 13:16 c
drwx------.  4 d     d     4096 Jan 28 13:20 d
drwxr-xr-x.  2 root  root  4096 Feb 25 18:26 Desktop
drwxr-xr-x.  2   501   502 4096 Jan 27 17:19 new
drwx------. 34 user1 user1 4096 Feb 29 17:25 user1
drwx------. 21 user2 user2 4096 Feb 28 09:43 user2
drwx------   4 user3 user3 4096 Feb 27 15:03 user3
FAQ
Q
how to set password expiration for user?
A
you can use "CHAGE" command to set expiration date.
Q
how to change a login shell?
A
You can make use of "CHSH" command to change login shell of linux.
Q
where i can find the configuration file for password and group?
A
Following is the location
/etc/passwd and /etc/group are the configuration file of password and group. And also you can use vigr and vipw command to open a group and password configurati
Q
What are all the commands to get who are all taking ssh with particular user?
A
"w" or "who" are the commands to get who are all taking ssh with particular user.
Q
how to manage "groups" and "group members" in linuxmint ?
A
You have to install Gnome2's "users and groups" utility to do that kind of advanced stuff. "sudo apt-get install gnome-system-tools"