xx is not in the sudoers file 问题解决

2429阅读 0评论2012-08-04 xu_liuzhen
分类:LINUX

xx is not in the sudoers file 问题解决

       在ubuntu中由于禁用了root用户,默认情况下会把安装系统时建立的用户添加到sudoers中。但在redhat和centos中并没有把任何root用户之外的用户默认的添加到sudoers之中。这样我们在执行sudo 命令时就会出现xxx is not in the sudoers file. This incident will be reported.这样的错误输出。现在为了安全起见比较提倡使用普通用户做日常操作,而在需要超级用户的时候使用sudo 来做,这样,我们就有必要把一些用户添加到sudoers之中。

       其实把用户添加到sudoers之中很简单。
首先利用whereis 命令查找sudoers配置文件的目录(默认会在/etc/sudoers):

[root@localhost nathan]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.bak /usr/share/man/man5/sudoers.5.gz


然后需要切换到root用户,有两种办法来修改 sudoers 的内容:
1. 直接使用专门修改命令:visudo ,直接编辑保存退出即可,此工具还会检测文件语法是否有错误
2. 更改/etc/sudoers的权限:

[root@localhost nathan]# chmod u+w /etc/sudoers

然后就可以利用vi编辑器来把用户添加到sudoers之中:

[root@localhost nathan]# vi /etc/sudoers

然后找到root    ALL=(ALL)       ALL所在的位置,把所要添加的用户添加到文件之中,

下面是添加完的结果。
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
liuz     ALL=(ALL)       ALL              (这一行是添加的内容,liuz是我的用户名)

然后需要把sudoers 的写权限去掉(否则系统不允许执行suoders文件):

[root@localhost nathan]# chmod u-w /etc/sudoers

至此,在退出root用户之后就可以利用sudo命令来执行超级用户的权限了。

上一篇:用vim编辑文件的时候,保存的时候发现权限不足,该怎么办?
下一篇:用awk数组去除重复域awk‘!a[$1]++’