CentOS 7中解决“xxx is not in the sudoers file”的问题
问题
今天在CentOS7中用非root用户执行命令(加sudo,sudo命令允许你以超级用户的身份执行命令)时,显示:
xxx is not in the sudoers file. This incident will be reported.
原因
原来只有用户属于wheel group组时才能使用sudo命令,可以使用usermod命令将用户添加到group组。
解决办法
usermod命令用于修改用户模式,通过usermod -aG wheel testuser可以将testuser用户添加到wheel组,这样testuser用户就能使用sudo命令了。
把用户添加到wheel组后,还需要确保/etc/sudoers文件中%wheel ALL=(ALL) ALL这一行没被注释(默认情况下是没被注释的),默认情况下/etc/sudoers文件只有读权限(是的,对root用户也只有读权限),若想编辑该文件可以使用一个特殊的工具组件——visudo,直接运行visudo命令将会打开/etc/sudoers文件,找到如下几行:
## Allows people in group wheel to run all commands%wheelALL=(ALL)ALL
可以看到%wheel ALL=(ALL) ALL这一行是否被注释。