1

Currently, I am receiving the following terminal error:

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

I have tried to utilise the guide found here to repair my /etc/sudoers file:

http://www.psychocats.net/ubuntu/fixsudo

I followed everything on a word per word basis and managed to re-write the sudoers file and add my user name (without the '@' symbol though) in the sudoers file to have full root permissions. I still get the sudo error(s) above.

Please don't be upset with me, I'm still relatively new to Linux and I was trying to learn more in depth procedures related to System Administration taken from the Linux Foundation course. I hope that my inquiry is well-received. I thank all of you for your help in advance. Peace and blessings unto you all.

  • 4
    Please post the broken sudoers file, so we can try to find the error. – Silent-Bob Oct 21 '15 at 5:48
  • Hello Silent-Bob thanks for your response. I had to go into the recovery mode of my ubuntu box to access it. I can not access it from the terminal because I get the above error. Is there a way to copy the /etc/sudoers file from the recovery mode? – Linuxn00b Oct 21 '15 at 5:50
  • 7
    Please use visudo next time to edit your sudoers file. It will refuse to overwrite the file while it still contains an error, helping prevent you shooting yourself in the foot! – roaima Oct 21 '15 at 7:03
  • Thank you, I definitely will. It's still a learning process for me. I'm really trying to catch up to you guys and other sys admins at becoming more adverse utliising Linux. Once again many thanks! – Linuxn00b Oct 21 '15 at 7:16
1

If sudo was your only way to access the root account, and you don't have a running root shell somewhere, you'll need to regain access to the root account by external means, typically requiring physical access to the machine. The most common way is to select “single user mode” or “recovery mode” at a boot prompt (you may need to perform some action such as pressing and holding Shift to make the boot prompt appear). How to do this depends on the bootloader is set up, which different distributions do differently, so look for documentation or tutorials related to your distribution.

If you aren't able to reach a root prompt in single user mode, you can get into an even more stripped down mode by adding init=/bin/sh to the kernel command line. You'll get to a root shell but you need to run a few commands to get a usable environment:

mount -t proc proc /proc
mount -o remount,rw /
bash

You can now edit the problematic file.

If you want multiple terminals in single user mode, you can open a new shell on another virtual console with the command openvt. Use Ctrl+Alt+F1, Ctrl+Alt+F1, etc. to switch between virtual consoles.

Don't edit sudoers directly. Use visudo. This command invokes an editor, then checks the syntax of the file, and aborts the modification if there's a syntax error. You can still lock yourself out, for example by removing the line that granted you access, but it does reduce the risk.

Ubuntu uses nano as the default editor. Many other distributions use vi by tradition. To pick a different editor, set the VISUAL environment variable, e.g.

export VISUAL=joe

You can use the directory /var/tmp as a temporary storage area if you want to make a copy of the file that you can read back after rebooting in normal mode. Make sure to make the file readable to your normal account.

cp /etc/sudoers /var/tmp
chmod a+r /var/tmp/sudoers

Tip: whenever you make changes that could affect your ability to access an account, keep a running shell in one window, and test your access in another window. If you aren't getting access, switch back to that running shell and fix the problem or revert the change immediately.

| improve this answer | |
0

I really appreciate the help. There was indeed an error in the sudo file I typed up in recovery mode. I was missing the closing quotation mark when specifying the paths in the "Defaults secure_path" (the " to be more precise) line. I was able to resolve the issue and I now have sudo up and running again :). Excellent!

Thank you very much for your help ladies and gentlemen.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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