您的位置:首页 > 运维架构 > Linux

linux为用户添加sudo权限sudo: /etc/sudoers is mode 0640, should be 0440?”

2013-10-04 18:24 381 查看


用sudo时提示"xxx is not in the sudoers file. This incident will be reported.其中XXX是你的用户名,也就是你的用户名没有权限使用sudo,我们只要修改一下/etc/sudoers文件就行了。下面是修改方 法:

1)进入超级用户模式。也就是输入"su -",系统会让你输入超级用户密码,输入密码后就进入了超级用户模式。(当然,你也可以直接用root用) ,如果从root切换其他用户如Karry,输入"su Karry".

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

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

4)然后保存(就是先按一 下Esc键,然后输入":wq")退出。 此时退出会有错误:E45:'readonly'
option isset(add!
to override),不能保存编辑后的文件。把保存命令换成:w!sudo
tee %,或者:x、:q!均不能保存usrName ALL=(ALL) ALL 这句代码,可以用visudo这个命令替代"vim /etc/sudoders"命令,编辑后用4)保存命令保存即可。至此步普通用户Karry已经可用sudo命令。

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

ubuntu或者CentOS中,/etc/sudoer 的权限为 0440时才能正常使用,否则sudo命令就不能正常使用。出现类似:sudo: /etc/sudoers is mode 0640, should be 0440 的对话。

解决办法:

1、Ctrl+Alt+F1 进入文本模式。用超级用户登录,如root

2、输入:chmod 0440 /etc/sudoers 。Enter

3、exit 退出

4、Ctrl+Alt+F7 返回图形模式。

5、在试试sudo命令,可以用了

P:其实另开一个端口,su -进入root,然后chmod 0440 /etc/sudoers

效果是一样的

example:

[BIngo@windows ~]$ sudo chmod u+w /etc/sudoers

口令:

[BIngo@windows ~]$ ls -l /etc/sudoers

-rw-r----- 1 root root 3210 11-16 02:40 /etc/sudoers

[BIngo@windows ~]$ sudo chmod u-w /etc/sudoers

sudo: /etc/sudoers is mode 0640, should be 0440

[BIngo@windows ~]$ ls -l /etc/sudoers

-rw-r----- 1 root root 3210 11-16 02:40 /etc/sudoers

另开端口

[root@windows ~]# chmod 0440 /etc/sudoers

[root@windows ~]# exit

[BIngo@windows ~]$ ls -l /etc/sudoers

-r--r----- 1 root root 3210 11-16 02:40 /etc/sudoers
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: