How to delete user account in Redhat/Ubuntu Linux?
Deleting user account in Linux is as a task to remove user login credentials from system configuration files such as /etc/passwd, /etc/shadow and files which are owned by that particular user from the Linux server. Here we are going to see on how to delete a user and precautions to be taken when deleting users. Lets start deleting user with examples.
Example1: Delete user account from a machine
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.
Lets see in our next post on how to add user to primary group.
Latest posts by Surendra Anne (see all)
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018
- Online training on Linux Bash shell scripting - February 8, 2018