首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

解决“grid is not in the sudoers file”有关问题

2013-11-15 
解决“grid is not in the sudoers file”问题用sudo时提示grid is not in the sudoers file. This inciden

解决“grid is not in the sudoers file”问题
   用sudo时提示"grid is not in the sudoers file. This incident will be reported.其中grid是你的用户名,也就是你的用户名没有权限使用sudo,我们只要修改一下/etc/sudoers文件就行了。

1.下面是修改方法:

1)进入超级用户模式。也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式。(当然,你也可以直接用root用)
2)添加文件的写权限。也就是输入命令"chmod u+w /etc/sudoers"。 (我开始以为在root身份可以省略,我以为root权限可以连这个都搞定,事实上,不是这样的)
3)编辑/etc/sudoers文件。也就是输入命令"vim /etc/sudoers",输入"i"进入编辑模式,找到这一 行:"root ALL=(ALL) ALL"在起下面添加"grid ALL=(ALL) ALL"(这里的grid是你的用户名),然后保存(就是先按一 下Esc键,然后输入":wq")退出。
4)撤销文件的写权限。也就是输入命令"chmod u-w /etc/sudoers"。
2.另一种修改sudoers的方法
sudo都提供了一个编辑该文件的命令:visudo来对该文件进行修改。强烈推荐使用该命令修改 sudoers,因为它会帮你校验文件配置是否正确,如果不正确,在保存退出时就会提示你哪段配置出错的。
(改命令需超级用户:su -) visodo /bin/sudoers
3.对sudoers文件详细讲解
A.首先写sudoers的缺省配置:
###########################################################
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

Defaults   env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
# Defaults specification
# User privilege specification
root    ALL=(ALL) ALL
# Uncomment to allow people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL
# Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL
# Samples
# %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users localhost=/sbin/shutdown -h now
########################################################
B。最简单的配置,让普通用户ubuntu具有root的所有权限
执行visudo之后,可以看见缺省只有一条配置:
root    ALL=(ALL) ALL
那么你就在下边再加一条配置:
ubuntu ALL=(ALL) ALL
普通用户ubuntu就能够执行root权限的所有命令。
以ubuntu用户登录之后,执行:
sudo su -
然后输入ubuntu用户自己的密码,就可以切换成root用户了。
C。让普通用户ubuntu只能在某几台服务器上,执行root能执行的某些命令。
首先需要配置一些Alias,这样在下面配置权限时,会方便一些,不用写大段大段的配置。Alias主要分成4种
Host_Alias
Cmnd_Alias
User_Alias
Runas_Alias
1) 配置Host_Alias:就是主机的列表
Host_Alias     HOST_FLAG = hostname1, hostname2, hostname3
2) 配置Cmnd_Alias:就是允许执行的命令的列表
Cmnd_Alias    COMMAND_FLAG=cmd1,cmd2,cmd3
3) 配置User_Alias:就是具有sudo权限的用户的列表
User_Alias USER_FLAG = user1, user2, user3
4) 配置Runas_Alias:就是用户以什么身份执行(例如root,或者oracle)的列表
Runas_Alias RUNAS_FLAG = operator1, operator2, operator3
5) 配置权限
配置权限的格式如下:
USER_FLAG HOST_FLAG=(RUNAS_FLAG) COMMAND_FLAG
如果不需要密码验证的话,则按照这样的格式来配置
USER_FLAG HOST_FLAG=(RUNAS_FLAG) NOPASSWD: COMMAND_FLAG
配置示例:
#
# Host alias specification
Host_Alias      EPG = 192.168.1.1, 192.168.1.2
# User alias specification
# Cmnd alias specification
Cmnd_Alias      SQUID = /opt/vtbin/squid_refresh, /sbin/service, /bin/rm
# Defaults specification
# User privilege specification
root    ALL=(ALL) ALL
ubuntu EPG=(ALL) NOPASSWD: SQUID

热点排行