ubuntu下执行sudo命令提示:xx is not in the sudoers file. This incident will be reported.

在执行sudo命令时会有如下提示:

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

ubuntu下执行sudo命令提示:xx is not in the sudoers file. This incident will be reported.

原因分析:一般这种情况是修改了用户名,没有对应修改sudoers文件或者group文件。

解决方法: 

 方法1:

如果除了root用户,还有别的用户,可以切换到别的用户,然后切换到root用户下,修改sudoers文件。

执行visudo命令,vi和sudo之间没有空格。或者vi  /etc/sudoers 命令,增加用户。

ubuntu下执行sudo命令提示:xx is not in the sudoers file. This incident will be reported.

ubuntu下执行sudo命令提示:xx is not in the sudoers file. This incident will be reported.

 方法2:

使用 su -命令(有空格,用"su"命令只是切换到root,而没有把root的环境变量传过去,实际是当前用户的环境变量,用"su -"命令会将环境变量传过去,和root登录效果一样),然后修改sudoers文件即可(visudo)。如果出现如下情况,别慌,只需要先进入recovery mode,然后修改sudoers文件即可。

ubuntu下执行sudo命令提示:xx is not in the sudoers file. This incident will be reported.

ubuntu进入recovery mode请参考: recovery mode

注:

username      ALL=(ALL:ALL) ALL                       #用户需要输入密码执行sudo命令

%groupname     ALL=(ALL) AL                             #用户组里的用户输入密码执行sudo命令

username  ALL=(ALL) NOPASSWD: ALL           #用户免密执行sudo命令

%groupname  ALL=(ALL) NOPASSWD: ALL      #用户组里的用户andy免密执行sudo命令