How to delete user in linux

How to Delete/Remove Users in Linux (userdel Command)

Linux is a multi-user system, which means that more than one person can interact with the same system at the same time. As a system administrator, you have the responsibility to manage the system’s users and groups by creating new users and assign them to different groups .

Occasionally, you might need to delete a user account. Perhaps because the user moved away from the organization, or it was created for a specific service that no longer runs on the system.

In Linux, you can delete a user account and all its associated files using the userdel command.

This tutorial covers the userdel command and its options.

userdel Command Syntax #

The syntax for the userdel command is as follows:

To delete users using the userdel command, you need to be logged in as root or a user with sudo access.

How to Delete User in Linux #

To delete a user account named username using the userdel command you would run:

When invoked, the command reads the content of the /etc/login.defs file. Properties defined in this file override the default behavior of userdel . If USERGROUPS_ENAB is set to yes in this file, userdel deletes the group with the same name as the user, only if no other user is a member of this group.

The command removes the user entries from the /etc/passwd and /etc/shadow, files.

In most Linux distributions, when removing a user account with userdel , the user home and mail spool directories are not removed.

Use the -r ( —remove ) option to force userdel to remove the user’s home directory and mail spool:

The command above does not remove the user files located in other file systems. You have to search for and delete the files manually.

If the user you want to remove is still logged in, or if there are running processes that belong to this user, the userdel command does not allow to remove the user.

In this situation, it is recommended to log out the user and kill all user’s running processes with the killall command:

Once done, you can remove the user.

Another option is to use the -f ( —force ) option that tells userdel to forcefully remove the user account, even if the user is still logged in or if there are running processes that belong to the user.

Читайте также:  Linux google test install

Conclusion #

In this tutorial, you learned how to delete user accounts in Linux using the userdel command. The same syntax applies for any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux.

userdel is a low-level utility, Debian and Ubuntu users will more likely use the friendlier deluser command instead.

Feel free to leave a comment if you have any questions.

Источник

How to Delete User in Linux

Linux is an operating system that is utilised by a wide variety of enterprises as well as people due to its power and widespread popularity. Users and the access levels they have to the system need to be managed, as is the case with any system. It’s possible that removing a user from the system will be necessary for certain circumstances.

This can be accomplished by using a variety of the available commands and settings in Linux. This article will provide a step-by-step guide on how to delete a user in Linux, as well as a table detailing the many options that can be selected when carrying out this action on a user that is logged into a server.

Introduction

In Linux, deleting a user requires deleting both the user account as well as the files that are connected with the user account. When a user no longer needs access to the system or has left the business, this feature may be helpful.

It may also be useful in other situations. Linux has several different commands that can be used to delete a user; however, the specific command and options that are executed may vary depending on the Linux distribution that is being used.

How to Delete User in Linux?

To delete a user in Linux, use the userdel command followed by the user’s username .

Here are two alternatives for writing this command:

Note: To execute these commands, you must have superuser capabilities or be logged in as root. Also, exercise caution when deleting users, as their data and files might get erased.

Let’s explore more about deleting a user in Linux in the following steps.

Here are the Steps to Delete a User in Linux:

Step 1: Log in to the Linux system using the root account or an account with sudo privileges .

Step 2: To delete a user account, use the userdel command.

The syntax for this command is as follows:

Steps to delete an user in Linux

Here, username is the name of the user account that you want to delete, and options are the various command-line options that can be used with the userdel command.

Some of the most commonly used options are listed in the table below:

Option Description
-r Delete the user’s home directory and files
-f Force the deletion of the user’s account, even if processes are still running
-Z Remove the user’s SELinux security context
-h Display help information for the userdel command
Читайте также:  Linux time время выполнения

Step 3: To delete a user and their home directory and files, use the following command:

Steps to delete an user in Linux

Here, username is the name of the user account that you want to delete.

Step 4: If you want to delete a user account even if there are processes still running under that user, use the following command:

Steps to delete an user in Linux

Here username is the name of the user account that you want to delete.

Step 5: If you want to remove the SELinux security context for a user, use the following command:

Here, username is the name of the user account that you want to delete.

Step 6: After you have deleted a user, you can also delete any groups that were associated with that user. To do this, use the groupdel command with the -f option, like this:

Steps to delete an user in Linux

Here, groupname is the name of the group that you want to delete.

Conclusion

  • Deleting a user in Linux involves removing the user account and associated files from the system. This can be done using the userdel command with various options depending on the requirements.
  • It is important to ensure that the user account is no longer needed before deleting it, as this action cannot be undone.
  • Furthermore, it is recommended to make a backup of any important files or data associated with the user account before deleting it.
  • Overall, managing user accounts is an essential task for Linux administrators and users. By following the steps outlined in this article, you can safely and effectively delete user accounts from a Linux system.

Источник

How to remove a Linux user

A computer system in an organization can be operated by a number of users, if someone leaves the organization his/her account becomes useless, it should be removed or deleted from the system to save storage space. If the operating system is Linux-based, the users can be managed using the terminal conveniently. In this follow-up, we are going to explain some simple queries through which we can remove the users from Linux.

How to remove a Linux user

To remove users from the Linux, first, we have to display the user, the user’s data is placed in the /etc/passwd directory, this cat is displayed using the cat command:

Scroll down to view the list of the users available in the Linux:

We have four users in Linux that are maadi, hammad, john, and paul which can be seen in the above output. We can remove or delete the users from Linux at any time by using the simple Linux command whose general syntax is:

The explanation to the above syntax is:

  • Use the userdel command to remove the user from Linux
  • Use any flag in the place of [options] that perform any specified function like “-r” which removes the additional files of the users
  • Replace the [username] with the actual user name which you want to remove or delete from Linux
Читайте также:  Полезные приложения для линукс

There are three types of most common options used with the userdel command are:

-f This option is used to forcibly remove the user from Linux, it terminates all the processes, logged out from the terminal, and finally removes the user permanently from Linux
-r This option is used to remove the files which are attached to the user
-Z SELinux user mapping is a security policy that is inherited by all Linux users, by using this option, you are independent of SElinux user mapping.

Let’s remove the user,” Paul”, from the Linux system using the command “userdel” with the sudo:

To verify the status of the last executed command, run the following command:

The command “echo $?” has the following possible outcomes which explanations are explained:

Outcome Explanation
0 The command was executed successfully.
1 The file contains the password, which cannot be updated
2 The command entered has invalid syntax
6 The user-specified in the command doesn’t exist
8 The user-specified in the command is currently logged in
10 The file contains groups, which cannot be updated
12 Unable to remove the home directory

Let’s assume there are some processes running in the background of user “john” due to which it is unable to remove it:

To resolve it, either forcibly remove the user using the option of “-f” with the userdel command or stop the processes. To stop the process, use the command:

Again, execute the command of userdel to delete the user john:

To verify the status, echo the command status:

The command is executed successfully.

Conclusion

In Linux, the user’s accounts that are not needed are just occupying the space and should be removed to make the space available for the new users. In Linux, this can be done very easily through the command-line, though the other option is still available and that is going through the Settings sections of the GUI of the Linux distribution and managing the users from there, the easy way to remove the users from Linux is explained in this write-up that is through the terminal. We just list down all users and remove the specified users which we want to remove by using the “userdel” command.

About the author

Hammad Zahid

I’m an Engineering graduate and my passion for IT has brought me to Linux. Now here I’m learning and sharing my knowledge with the world.

Источник

Оцените статью
Adblock
detector