Error xxx is not in the sudoers file. This incident will be reported solution in Centos

Introduction - Explanation of the cause of the error

xxx is not in the sudoers file. This incident will be reported "The solution
is the problem of not obtaining the highest authority . Sometimes it is not possible to solve the problem by adding sudo. Different versions of different systems have different methods of obtaining the highest authority.

Method 1: Permanently obtain the highest authority

Step 1 : Switch to the root user to log in to the system
insert image description here

Be sure to switch to root user login

Step 2: Open the command line and enter the following

chmod u+w /etc/sudoers

insert image description here

The purpose of this step is that the /etc/sudoers file is read-only by default , and it is also for root, so you need to add the write permission of the sudoers file first

Step 3: Enter vim /etc/sudoers

vim /etc/sudoers

As shown in the figure below, find line 91 , enter xxx ALL=(ALL) ALL under it, xxx is which user you want to obtain the highest authority, my ordinary user is localhost

insert image description here
After editing, press the Esc key and enter: wq to save and exit,
then reboot to restart ok

Tips: Let me talk about the meaning of the statement just entered on line 92:
you can sudoers add any of the following four lines
youuser ALL=(ALL) ALL
%youuser ALL=(ALL) ALL
youuser ALL=(ALL) NOPASSWD: ALL
% youuser ALL=(ALL) NOPASSWD: ALL

The first line: allow the user youuser to execute the sudo command (password required). The
second line: allow users in the user group youuser to execute the sudo command (need to enter the password). The
third line: allow the user youuser to execute the sudo command, and execute Do not enter the password.
The fourth line: Allow users in the user group youuser to execute the sudo command, and do not enter the password when executing.

Method 2: How to log in remotely as root

Step 1:
Still using root to log in to the system, open the command line and enter the following

 vi /etc/ssh/sshd_config

As shown below:

insert image description here
Step 2:
Find #PermitRootLogin yes, remove the # in front, that is, uncomment
insert image description here

After editing, press the Esc key and enter: wq to save and exit,
then reboot to restart ok

Method 3: Let ordinary users belong to the wheel group, and the wheel group can obtain the highest authority

Step 1:
Log in to the system with root, open the command line, and enter vim /etc/sudoers

vim /etc/sudoers

insert image description here

Step two:

find #%wheel ALL=(ALL)

# %wheel   ALL=(ALL)    NOPASSWD:ALL

remove the leading #

%wheel   ALL=(ALL)    NOPASSWD:ALL

After editing, press the Esc key and enter: wq to save and exit,
then reboot to restart ok

Guess you like

Origin blog.csdn.net/weixin_43419816/article/details/127030199