centos/Linux 解决使用sudo命令时xxx is not in the sudoers file.This incident will be reported

解决方法

切换到root用户:

su

然后在root用户下输入命令:

chmod u+w /etc/sudoers
vim /etc/sudoers

vim编辑器界面输入/root查询到这一行:

root    ALL=(ALL)       ALL

在这一行的下面输入:

你的用户名      ALL=(ALL)       ALL

保存后退出,再恢复掉文件不可写的权限:

chmod u-w /etc/sudoers
exit

然后就可以使用sudo

问题解析

报错原因是:当前用户没有使用sudo的权限

解决方法就是:让当前用户有使用sudo的权限,在写入时:

用户名	ALL=(ALL)	ALL # 允许用户执行sudo
%用户名	ALL=(ALL)	ALL # 允许用户组执行sudo
用户名	ALL=(ALL)	NOPASSWD: ALL # 允许用户不用密码执行sudo
%用户名	ALL=(ALL)	NOPASSWD: ALL # 允许用户组不用密码执行sudo

猜你喜欢

转载自blog.csdn.net/weixin_35757704/article/details/121225923