How to delete user account in Redhat/Ubuntu Linux?

Example1: Delete user account from a machine

userdel username


userdel surendra

The disadvantage of the above command is that it only deletes users login details but not his home directory.

Example2: Deleting user account and his home directory from a Linux machine

userdel -r username

-r stands for remove home directory as well

The disadvantage of above two commands are that they will not delete user files which are scattered across the machine such as his personal files, his mail spool etc.

There is an excellent user deleting command with more options such as deleting entire user files, the command is deluser. We will see some examples of this command

Example3: Delete user account forcefully though user logged in.

deluser –force username

Example4: Delete user account along with his home directory

deluser –remove-home username

Example5: Delete user account along with his home directory and his personal files which are located in different locations which you are not aware.

deluser –remove-all-files username

Example6: Delete user account and take backup of his files to a directory for future use by the company.

deluser –backup-to DIR username

Example: I want to delete user account Don and take backup of all his files to /var/backup

deluser –backup-to /var/backup don

Note: When you take backup, the backup file is created as /var/backup/don.tar.gz file.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s