Sudo不起作用

我在/ etc中编辑了我的sudoers文件,之后我再也不能使用sudo了。 每当我发出命令时,我都会得到这个:

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

怎么解决?

从GRUB菜单启动进入恢复模式(在启动过程中按住SHIFT键以显示此菜单),输入root shell。

  1. 首先你需要写权限来编辑sudoers,所以运行

     mount -o remount,rw / 
  2. 然后使用visudo并恢复你的错误。 visudo将检查生成的sudoers文件是否符合所需的语法。

    默认情况下, visudo使用vi作为编辑器,但您可以告诉它使用您喜欢的文本编辑器和EDITOR环境变量,例如:

     EDITOR=nano visudo 

有同样的问题,

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

更容易解决的方法是:

 pkexec visudo 

以下是Ubuntu的默认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 # Uncomment to allow members of group sudo to not need a password # %sudo ALL=NOPASSWD: ALL # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL) ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL 

我希望它会帮助你我的朋友。

您也可以使用您喜欢的任何文本编辑器编辑/etc/sudoers

 EDITOR=gedit visudo 

会使用gedit。 但你应该从shell运行它。 否则您将无法读取错误消息。

这为我解决了同样的问题:

 pkexec chmod 440 /etc/sudoers pkexec chmod 775 /etc/sudoers.d pkexec chmod 440 /etc/sudoers.d/README