CentOS 7中解决“xxx is not in the sudoers file”的问题

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
%wheel	ALL=(ALL)	ALL

可以看到%wheel ALL=(ALL) ALL这一行是否被注释。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值