Linux Delete User

This post will guide you how to remove a user account in Linux operating system. How do I delete a user account with home directory under CentOS/RHEL/Ubuntu Linux system.

Revmoe Linux User


If you want to delete a Linux user, you can use the userdel command under command line interface. and this command can be used to delete a Linux user, and it also can be used to delete home directory and its files in Linux. and it also can be used to removed user information from the /etc/passwd,/etc/shadow and /etc/group files.
Assuming that you have a user account called osetc, and you want to delete it from the current Linux system, you can issue the following command:

#userdel osetc

Outputs:

[root@osetc_x8664 ~]# userdel osetc
[root@osetc_x8664 ~]# id osetc
id: osetc: no such user

[root@osetc_x8664 ~]# ls /home
opc oracle osetc
[root@osetc_x8664 ~]#

From the above outputs, the user osetc has been removed from the linux system, but its home directory and files still exist.

If the user is still logged in, and you want to force the removal of the current Linux user, you can use the userdel command with -f option. type:

#userdel -f osetc

Outputs:

[root@osetc_x8664 ~]# userdel -f osetc
[root@osetc_x8664 ~]# id osetc
id: osetc: no such user

If you want to delete one Linux user and its home directory and mail spool, you need to user the userdel command with -r option. type:

#userdel -r osetc

Outputs:

[root@osetc_x8664 home]# userdel -r osetc1
[root@osetc_x8664 home]# ls
opc oracle osetc

You might also like:

Sidebar



back to top