我如何修复破坏的sudo-sudo:在第23行附近的/ etc / sudoers中解析错误?

我收到此错误:

sudo: parse error in /etc/sudoers near line 23 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin 

我试图禁用密码身份validation,所以每次我想安装东西时都不必输入密码,但我可能以不太好的方式更改密码。 我是Ubuntu的新手,我厌倦了Windows 🙂

到目前为止,我发现有些人建议在单用户模式下启动,但我害怕更糟糕的事情。

我该如何解决这个错误?

解决这个问题很简单, 在askubuntu的其他地方也可以解决 。

简短回答,使用:

 pkexec editor_of_choice 

在启动时立即按住Shift键,以便获得GRUB屏幕。 选择恢复模式。 选择放入根终端。 运行mount -n -o remount,rw /然后是visudo 。 它可以让你修复文件的问题并保存。 它不会让您保存格式错误的文件。

Folowing解决方案适用于远程服务器,它可以工作!

http://ubuntuforums.org/showthread.php?t=2036382&p=12144840#post12144840

然后只需用visudo来添加轮子


  1. 重命名当前文件

    mv /etc/sudoers{,.bak}

  2. 使用以下基本内容创建一个新的vi /etc/sudoers

     # /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 
  3. 运行visudo并添加自定义内容。

你可以这样做:

创建一个副本

 cp /etc/sudoers /etc/sudoers.bak 

在那里编辑问题部分

 vim /etc/sudoers.bak 

替换原始sudoers文件

 cp /etc/sudoers.bak /etc/sudoers 

这个对我有用。

如果你搞砸了你的sudoers文件。你需要:

  • 重启进入恢复模式(在启动时点击退出,在grub屏幕上选择恢复模式选项)
  • 选择“启用网络”选项(如果不是,您的文件系统将以只读方式挂载。谁知道)
  • 选择’Drop to root shell’选项
  • 运行visudo,修复你的文件
  • 使用普通grub选项重新启动

来源: – http://mario.net.au/content/recover-etcsudoers-ubuntu-1204

我搞砸了sudoers文件,发现我不记得root密码了。 解决方案:在Windows下重新启动(我有双启动)并使用ext2fsd编辑文件(安装后必须重新启动)。 原则上,这可能是另一个Linux或实时闪存,不一定是Windows。