Ubuntu中出现user name is not in the sudoers file.This incident will be reported的错误


使用环境Ubuntu Linux系统下:

在学习鸟哥的私房菜时,使用了如下命令

usermod -G users username

username为你自己的用户名。

由于没有使用-a参数导致我的用户被分到了users用户组里,而原先的用户组被重置掉,仅剩下users用户组

由于没有sudo用户组,因此无法使用sudo的命令。

解决方法:在x-windows图形界面下reboot系统

然后进入grub界面选择选中的项

\

选择fsck,等待30秒左右

\

点击root项进入root下的命令行

\

在命令行中输入

usermod -a -G sudo username
usermod -a -G adm username

有的系统是admin,但我的系统是adm,不过我看了sudoers文件里的内容中用的是admin,

在我的/etc/group中没有admin这一项,所以我添加adm是无法让我的用户使用sudo的,因此还是要加入sudo用户组

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
 
# Host alias specification
 
# User alias specification
 
# Cmnd alias specification
 
# User privilege specification
root    ALL=(ALL:ALL) ALL
 
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
 
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
 
#includedir /etc/sudoers.d

然后点击resume重启系统

\

重启后就可以进入root了。

如果你可以直接用su - 命令直接进入超级root用户,那么就可以直接修改/etc/sudoers文件

并改动username用户所属的用户组。

相关内容