CentOS

How to Remove User from Sudoers Centos 8

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:

$ sudo userdel linuxhint

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:

$ sudo visudo

Scroll down the file until you get the given line:

root ALL=(ALL) ALL

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

linuxhint ALL=(ALL) ALL

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.

About the author

Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.