10

This question already has an answer here:

I edited my sudoers file in /etc and after that I can't use sudo anymore. I get this whenever I issue the command:

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

How to solve it?

marked as duplicate by Eliah Kagan, karel, Videonauth, Eric Carvalho, dessert Dec 8 '17 at 23:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8

Boot into recovery mode from the GRUB menu (hold the SHIFT key during boot to reveal this menu), enter the root shell.

  1. First you need write permission to edit sudoers, so run

    mount -o remount,rw /
    
  2. Then use visudo and revert your mistake. visudo will check if the resulting sudoers file conforms to the required syntax.

    By default visudo uses vi as editor, but you can tell it to use your favourite text editor with the EDITOR environment variable, e. g.:

    EDITOR=nano visudo
    
  • 2
    Please include in your answer an advice to use visudo to make any change to the sudoers file. – Eric Carvalho Jul 31 '12 at 1:24
23

Had the same problem,

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

Easier way to fix it is :

pkexec visudo 
  • No joy; The program 'pkexec' is currently not installed. You can install it by typing: sudo apt-get install policykit-1 – Koen. Nov 12 '14 at 22:37
  • 1
    Seems to be installed in 14.04. This fix also works for corrupt overrides in sudoers.d, via pkexec visudo -f /etc/sudoers.d/myOverrides. – Heather Turner Mar 12 '15 at 9:51
  • it's installed as default in 15.04 too. Worked great for this situation. – Michal Illich Jul 8 '15 at 15:50
  • I believe this only works if your current user has a password, eg., it fails for those who ssh into machines with an unset password. – tedder42 Oct 9 '17 at 18:19
1

Below is the default sudoers file for Ubuntu:

# /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

I hope it will help you my friend.

  • 3
    As of Ubuntu 12.04, this is no longer the default (since sudo is now the group that confers administrative abilities, though in upgraded systems admin still exists and serves its usual function). – Eliah Kagan Aug 31 '12 at 22:37
1

You could also edit /etc/sudoers with any text editor you like:

EDITOR=gedit visudo

would use gedit for it. But you should run it from shell. Otherwise you wouldn't be able to read error-Messages.

1

This fixed the same problem for me:

pkexec chmod 440 /etc/sudoers

pkexec chmod 775 /etc/sudoers.d

pkexec chmod 440 /etc/sudoers.d/README

Not the answer you're looking for? Browse other questions tagged or ask your own question.