问题
在 centos 中使用非 root 用户执行 sudo 命令的时候会提示:xxx is not in the sudoers file. This incident will be reported.
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
解决方案
出现以上问题是因为普通用户没有被授予 sudo 权限
解决办法是修改 /etc/sudoers
文件,添加如下配置:
common ALL=(ALL) ALL
%common ALL=(ALL) ALL
%common ALL=(ALL) NOPASSWD:ALL
common ALL=(ALL) NOPASSWD:ALL
解释说明:
第一行:允许用户 common 执行 sudo 命令(需要输入密码)
第二行:允许用户组 common 里面的用户执行 sudo 命令(需要输入密码)
第三行:允许用户 common 执行 sudo 命令(无需输入密码)
第四行:允许用户组 common 里面的用户执行 sudo 命令(无需输入密码)
Tips: 若无 /etc/sudoers
文件的写权限,则暂时执行如下命令赋予写权限后再复原,避免误操作
# 赋予 root 写权限
chmod u+w /etc/sudoers
# 改回只读权限
chmod 440 /etc/sudoers