14

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?

2

5 Answers 5

27

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 
5
  • 1
    No joy; The program 'pkexec' is currently not installed. You can install it by typing: sudo apt-get install policykit-1
    – Koen.
    Nov 12, 2014 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. Mar 12, 2015 at 9:51
  • it's installed as default in 15.04 too. Worked great for this situation. Jul 8, 2015 at 15:50
  • 2
    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. Oct 9, 2017 at 18:19
  • @tedder42 I think so as well
    – The Onin
    Jan 9, 2021 at 16:16
10

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
    
1
  • 2
    Please include in your answer an advice to use visudo to make any change to the sudoers file. Jul 31, 2012 at 1:24
2

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
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.

1
  • 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). Aug 31, 2012 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.

0

Not the answer you're looking for? Browse other questions tagged .