Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决

Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决

参考:https://blog.csdn.net/lichangzai/article/details/39501025

 

如果执行sudo命令的用户没有执行sudo的权限,执行sudo命令时会报下面的错

[[email protected] ]# sudo yum install gcc-c++ 
rootr is not in the sudoers file.This incident will be reported

设置用户执行sudo命令权限,建议这些操作都在secureCRT内进行要不然当走到进入sudoers那一步时,会出现问题
方法如下:    
1、进入超级用户模式。也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式。

2、添加文件的写权限。也就是输入命令"chmod u+w /etc/sudoers"。

Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决

 
3、编辑/etc/sudoers文件。也就是输入命令"vim /etc/sudoers",输入"i"进入编辑模式,
找到这一行:"root ALL=(ALL) ALL"在起下面添加"xxx ALL=(ALL) ALL"(这里的xxx是你的用户名),比如我这里是rootr所以我的语句是:rootr ALL=(ALL) ALL

Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决

如果要让执行时不需要输入密码,再找到下面这一句
# %wheel  ALL=(ALL)       NOPASSWD: ALL

并去掉注释#:
%wheel  ALL=(ALL)       NOPASSWD: ALL

然后保存(就是先摁一下Esc键,然后输入":wq")退出。

4、将你的用户(普通用户)调整至“ wheel ”用户组里面。
gpasswd -a YourUserName wheel

这样,就可以每次执行 sudo 命令时不再输入密码了

5、撤销文件的写权限。也就是输入命令"chmod u-w /etc/sudoers"。

[[email protected] ]$ su root
[[email protected] ]# chmod u+w /etc/sudoers
[[email protected] ]# vim /etc/sudoers
[[email protected] ]# chmod u-w /etc/sudoers
[[email protected] ]# gpasswd -a rootr wheel

[[email protected] ]# su rootr

 

截图:

Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决

 之后就可以执行sudo啦,截图留念:

Linux中新建用户用不了sudo命令问题:rootr is not in the sudoers file.This incident will be reported解决