您的位置:首页 > 其它

因修改/etc/sudoers权限导致sudo和su不能使用的解决方法

2014-04-22 21:37 288 查看
  系统环境:ubuntu 12.04

状况:

  因为修改了/etc/sudoers以及相关权限,导致sudo无法使用,恰好Ubuntu的root密码没有设置。

  错误如下:

  ~$ sudo
  sudo: >>> /etc/sudoers:syntax error 在行 21 附近<<<
  sudo: /etc/sudoers 中第 21 行附近有解析错误
  sudo: 没有找到有效的 sudoers 资源,退出
  sudo: 无法初始化策略插件


  于是,只能进去单用户模式(拥有root权力)去修改,在Ubuntu下,开机时长按shift出现各种模式,选择第二个recovery mode,按e进去编辑。

解决方法:

1、重启ubuntu,启动时按Esc或Shift键,可以看到引导选项;

2、在引导选项中选择Recovery模式的那一项来引导;

3、进入Recovery Menu页面,选择root,也就是进入试用root用户进行系统恢复,在这里可以执行超级用户的权限的操作,回车后可以看到熟悉的 root@user ~# 命令提示符;

4、设置或者撤销/etc/sudoers文件的权限,也可以将该文件改回到发生错误之前的状态。

chmod 666 /dev/null
mount -o remount rw /
vi /etc/sudoers
恢复本文件内容并存盘


5、退出Recovery模式,重新启动ubuntu。

  PS:当然也可以用ubuntu光盘引导系统,然后mount相应的磁盘,然后修改/etc/sudoers文件,进入系统,就可以正常启动了(linux使用熟练的话不妨一试)。

# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults env_reset

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL=(ALL) ALL

# Allow members of group sudo to execute any command after they have
# provided their password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐