解决Linux下“XX is not in the sudoers file. This incident will be reported.”的问题

如果普通用户需要暂时使用到root用户才具有的权限,我们可以通过sudo指令实现对该条指令暂时的“提权”,而我们在使用该指令时会发生这样的问题:

XX is not in the sudoers file.  This incident will be reported.

image-20230403194224573

该段提示告诉我们,该用户不是受信任用户,不允许提权操作!

因此我们要使用vim,将该用户添加到受信任用户中去,以实现sudo,具体步骤如下:

step 1:切换成root用户

image-20230403204342551

step 2:编辑sudoers文件

ls /etc/sudoers
vim /etc/sudoers

用vim编辑该文件,找到如下行(大概在100行左右),添加受信任用户
image-20230403205154030

进入底行模式(shift+:)输入:

w!     #强制写入
q!     #强制退出

step 3:验证

image-20230403205510144
此时能正常使用sudo提权指令!

猜你喜欢

转载自blog.csdn.net/kevvviinn/article/details/129939796