Geekdosage
  • Home
  • Computer hardware
    • GPU
      • AMD
      • Nvidia
    • Processor
  • Linux
    • CentOS
    • Ubuntu
  • Docker
  • Computer Software
    • Operating System
      • Windows
      • MacOS
      • Android
  • Gaming
  • Computer Science
    • Network Engineering
    • Comparisons
  • About Us

Geekdosage

  • Home
  • Computer hardware
    • GPU
      • AMD
      • Nvidia
    • Processor
  • Linux
    • CentOS
    • Ubuntu
  • Docker
  • Computer Software
    • Operating System
      • Windows
      • MacOS
      • Android
  • Gaming
  • Computer Science
    • Network Engineering
    • Comparisons
  • About Us
CentOSLinuxUbuntu

How to remove/delete user in Linux

by GeekDosage January 11, 2021
written by GeekDosage January 11, 2021
User delete in Linux

As a System administrator, you have to maintain Linux servers up to standards with your organizational policies. Therefore there may be some situations where you may need to remove the existing users. Linux permits you to remove existing users from the Linux server. Once the user is removed, the user’s SSH access on the server would be revoked. All the files related to the users also can be deleted with directory ownership. with this tutorial, Let’s learn how to remove a user from Linux.

Prerequisites

root user access or non-root user with sudo privileges

How to use Linux to Remove User?

Step by step guide to removing user in Linux

1) First login to the server with user login/using the SSH. 

2) type the below command. It will switch to the root user if you are not the root.

$ sudo su -

3) Next, run the userdel command to remove the user. 

$ userdel user-name

4) Done. The user will be deleted securely.

Delete/Remove Users in Linux

Linux can operate on a multi-user level and the system can handle more than one user to access the core functionalities of Linux. The user gets permission to interact with the system at the same time when another user is accessing the data. It is system administrators who take care of the new user creation/deletion and group activity. 

You get the rights to create new users and assign them to different groups based on their tasks. Each group would have predefined permission. 

You get to set the group level permission, which restricts all the users from private access to data. You can assign the user’s role and responsibilities in the group.

There will be a time when you want to delete the user account in the Linux operating system. Perhaps the user’s job is complete, or the user may have moved to the other organization. 

In this case, keeping the user’s access to the systems may create vulnerability or a data leak, which will be a costly affair. 

You can use this command to remove the particular users without damaging the other profiles. It is the safest way to delete specific data.

To delete the user account with the user’s home and mail spool, run the below command.

$ userdel -r user-name

Mention the username after the userdel command. Once you invoke the command, the Linux system will search for the username’s exact match and identify the final output that will be deleted in the process.

How verify user delete status in Linux

after running the userdel command, you can check the exit code to verify the command execution status. You can understand the user delete status in the Linux system with the output value.

Run the following command after the userdel command.

$ echo $?

These are the expected output values with the explanation.

0: success

1: can't update password file

2: invalid command syntax

6: specified user doesn't exist

8: user currently logged in

10: can't update group file

12: can't remove home directory

if the command exits as a success, it completely removes the user, user’s access to the server, user’s home directory, and the mail spool.

When deleting the user account without -r option, you should note that the user home and mail spool directories are not removed. 

Additionally, the user’s file stored in the other system would not be deleted using the above command. You need to search for the file and use the manual process to delete them.

User not removed after running the command

There are chances that the user will not be removed from the system if the user logged into the system. The user delete command will be terminated, and it will prompt the error message that the process is unsuccessful. The user has to be sign-out before you delete the files from the system.

Suppose such a situation occurs where users are still log in, ask them to log out from the system. After the process is complete, you have to run the kill all process command to terminate all the background processes activated by the users. 

The killall command identifies the active processes related to the user and start terminating them one by one.

$ sudo killall -u user-name

Once the process of killing all background files is done, you may remove the user from the system.

There are several other ways you can delete the user. The force delete is one of the options available in Linux. 

When you run the -f force command in Linux, the command tells the system to find the given user name and remove it forcefully. 

The command is effective and enables the administrator to remove the user’s account event forcefully. The user is logged into the system. All the running process of the users will be terminated.

Available options with userdel command

-f: The f in the command stands for force removal. When you run this command, the selected username will be forcefully terminated as well as logged out from the system. All the processes running in the background also stopped.

-r: If you want to remove the additional files such as the home directory and mail 
    spool, then you should use this command.

-Z: The command line would help you remove SELinux user mapping for the users. 

All of the above commands are highly secure. It does the job smoothly without any error. Suppose any of the commands are not able to detect the users. 

Kindly verify the user’s name again. The username use in the command line is case sensitive, so any typing mistake would result in an error while running the command. 

Also, type the command line correctly. If there is a typo mistake, the command will not perform correctly, and the system will show an error while processing the data. 

Each command performed on the Linux system is species. Once you know the command, you can easily control the Linux system and do whatever process you want to run on the system without any trouble. The Linux system ensures higher security to the stored data. 

Moreover, Control the logged in users and monitor the activity to avoid any malpractice on the system.

Conclusion

I hope the Linux guide has helped you learn how to delete the user’s account in Linux using the userdel command. The syntax is common for the Linux distribution, Ubuntu, Debian, and all other Linux supported software and applications.

Read more:

How to rename a directory in Linux?
How to change the forgotten root password in CentOS 8
GeekDosage
0 comment
0
FacebookTwitterPinterest
previous post
How to rename a Directory in Linux?
next post
2 Simplest Methods to Take/Capture Desktop Screenshot in Ubuntu

Related Posts

2 Simplest Methods to Take/Capture Desktop Screenshot in...

January 17, 2021

How to rename a Directory in Linux?

January 5, 2021

How to Install VirtualBox in Ubuntu 20.04

January 3, 2021

How to Create a Private Docker Registry in...

December 23, 2020

How to Build a Docker Image from Dockerfile

December 14, 2020

How to Install Docker in Ubuntu 20.04

December 12, 2020

How to Install Docker on CentOS 7

December 10, 2020

How to change the forgotten root password in...

November 25, 2020

What is a Linux OS? Why Linux is...

August 12, 2020

What is an operating system ? ~ Why...

August 12, 2020

Leave a Comment Cancel Reply

Save my name, email, and website in this browser for the next time I comment.

In This Article

  • 1 Prerequisites
  • 2 How to use Linux to Remove User?
    • 2.1 Step by step guide to removing user in Linux
  • 3 Delete/Remove Users in Linux
  • 4 How verify user delete status in Linux
  • 5 User not removed after running the command
  • 6 Available options with userdel command
  • 7 Conclusion
  • 8 Read more:

Keep in touch

Facebook Twitter Google + Instagram Pinterest Email

Popular Posts

  • How to change the forgotten root password in CentOS 8

  • How to Install Docker on CentOS 7

  • How to Build a Docker Image from Dockerfile

  • Best GPU stress test software to test your GPU

About Geekdosage

Geekdosage is a technology based website which mainly focuses on network engineering, computer science, automation, computer hardware and software and internet technologies. Our purpose is to create a platform where anyone can access the subject areas without barriers.

Recent Posts

  • 2 Simplest Methods to Take/Capture Desktop Screenshot in Ubuntu

    January 17, 2021
  • How to remove/delete user in Linux

    January 11, 2021

Find us

Facebook Twitter Instagram Pinterest Email
  • About Us
  • Contact Us
  • Disclaimer
  • Terms and Conditions
  • Cookie Privacy policy
  • Privacy Policy
  • DCMA

@2021 - All Right Reserved | Designed and Developed by GeekDosage