xx is not in the sudoers file问题的解决方案


xx is not in the sudoers file 问题解决的两种方案如下。。。。。  
两种方法执行命令不同而已,原理其实一样
  www.2cto.com  
方法一:
首先利用whereis 命令查找sudoers配置文件的目录(默认会在/etc/sudoers)
[root@localhost xiaofei]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.bak /usr/share/man/man5/sudoers.5.gz
然后需要su -切换到root用户,更改/etc/sudoers的权限
[root@localhost xiaofei]# chmod u+w /etc/sudoers
 
然后就可以利用vi编辑器来把用户添加到sudoers之中:
[root@localhost xiaofei]# vi /etc/sudoers
然后找到root    ALL=(ALL)       ALL所在的位置,把所要添加的用户添加到文件之中,
下面是添加完的结果:
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
xiaofei ALL=(ALL)       ALL              (这一行是添加的内容,xiaofei是用户名)
 
然后需要把sudoers 的写权限去掉:
[root@localhost xiaofei]# chmod u-w /etc/sudoers
如果不去掉写权限,系统不允许执行suoders文件,运行sudo命令时会出现以下错误:
sudo: /etc/sudoers is mode 0640, should be 0440                                 www.2cto.com  
至此,在退出root用户之后就可以利用sudo命令来执行超级用户的权限了。
 
方法二:
首需要切换到root身份
$su -
(注意有- ,这和su是不同的,在用命令"su"的时候只是切换到root,但没有把root的环境变量传过去,还是当前用户的环境变量,用"su -"命令将环境变量也一起带过去,就象和root登录一样)
 
然后
$visudo    //切记,此处没有vi和sudo之间没有空格
 
1、移动光标,到最后一行
2、按a,进入append模式
3、输入
your_user_name    ALL=(ALL)    ALL
4、按Esc
5、输入“:wq”
 
这样就把自己加入了sudo组,可以使用sudo命令了。

相关内容

    暂无相关文章