Adding and removing the users are the most basic functions when getting started with the centOS 8. We may need to have many users and allow them sudo permissions. And sometimes, due to security purposes, you want to remove them from the host.

The account with the sudo privileges can run the system as an administrator that a normal user cannot. These privileges allow the user to act as a root user through which the user can perform all the administrative tasks or commands.

It is not compulsory to assign the root password to every user. If you assign them sudo permissions, they will have access to perform all the operations without knowing the root password.

Similarly, you can get back the sudo permissions from the users by deleting their accounts. Follow the guide to learn multiple approaches:

How to Delete User from Sudoers File on CentOS:

When a user is added to the device, the “sudoers” file keeps the record. The sudoers file is used to manage the user’s record, including who the user is, what functions the user performed, and where, etc.

Several ways are introduced to delete users from the centOS. By following the guide, you will learn two approaches:

  1. Through the userdel command
  2. Through the sudoers file

How to delete user from CentOS using the “userdel” command:

Using the “userdel” command, it is very simple to remove a user from the account.

Open a terminal and type:

$ sudo userdel <username>

Suppose, to delete the user account “linuxhint,” the command would be:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/word-image-320.png" data-lazy- height="102" src="data:image/svg xml,” width=”814″>

To delete a user account through the “userdel” command is not enough sometimes; there might be a case that its respective files or data could be saved in the home directory.

So, to remove a user with its associated data from the home directory, use the “-r” option:

$ sudo userdel -r <username>

How to delete user from CentOS using sudoers file:

When we remove the user from the CentOS, it is possible that the sudoers file still has its information.

So, run the “visudo” command to find the sudoers file:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/word-image-322.png" data-lazy- height="59" src="data:image/svg xml,” width=”798″>

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/word-image-324.png" data-lazy- height="478" src="data:image/svg xml,” width=”796″>

Scroll down the file until you get the given line:

Right after this line, you will see the user’s name entry:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/06/echo/word-image-326.png" data-lazy- height="360" src="data:image/svg xml,” width=”800″>

Remove this line, and the user will no longer be found in the sudo group.

Conclusion:

While using CentOS 8, adding and removing other users are the most common tasks you should know about. We need to add users for several reasons, but sometimes, we have to take privileges back due to security reasons. Through the sudo privileges, one can access run administrative tasks without knowing the root password even.

The guide was discussing how you can delete a user from the sudeors file. Although a user can be deleted several ways, we have discussed the two simple approaches, using the userdel command and sudoers file.