Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Possible Duplicate:
Ubuntu : borked my sudoers file, how can I fix it?

Problem description:

I have broken my /etc/sudoers file by making a typo in it. Now I can no longer use any sudo commands as the below error is thrown. Therefore I can't fix my sudoers file and am effectively stuck.

$ sudo nano /etc/sudoers
>>> /etc/sudoers: syntax error near line 39 <<<
sudo: parse error in /etc/sudoers near line 39
sudo: no valid sudoers sources found, quitting

I found few solutions saying I should boot into recovery mode (like the one below) which I would obviously like to avoid.
Ubuntu : borked my sudoers file, how can I fix it?

Questions:

-Are there any other ways to fix it without restarting ubuntu?
-If it is so easy to lock yourself out of sudo when modifying the sudoers file (everybody can do a typo), why isn't the sudoers config read from memory instead of the file directly? There would be a command (e.g. sudo-load) that would make sure the syntax is OK before loading the config into memory thus avoid this sort of problems.

Solutions:
There seems to be 2 ways of recovering it:
-if you have the root password you can simply issue a 'su' and then edit the file
-if you don't have the root password you need to restart into single user mode

share|improve this question

marked as duplicate by ThatGraemeGuy, Iain, RobM, Chopper3 Mar 24 '11 at 11:55

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.

3  
This answer on the question you linked to tells you all you need to know. Even the /etc/sudoers file itself has a comment warning you to always use visudo to edit it. –  ThatGraemeGuy Mar 24 '11 at 8:45
    
this is why i now always set a root password immediately after install. Got burnt the same way myself, on a remote machine I had no access to. –  Sirex Mar 24 '11 at 10:04

1 Answer 1

up vote 10 down vote accepted

Nope, you have to reboot, or log in as root if you allow root logins.

This is the reason you should always use visudo when you modify the sudoers file. visudo will check the syntax of the sudo file before saving it, protecting you from this specific problem (but not from writing a sudoers file that disallows you from running sudo!)

Note that sudoers is normally setup to not be writable even by root on Ubuntu:

-r--r----- 1 root root 556 2010-04-18 15:05 sudoers

So you must have changed the access rights on sudoers to modify it with nano. There is a very good reason files are setup like this. If you come across a file that is not writable by root you should think one, two and three times before you change access rights and start editing it.

share|improve this answer
    
My sudoers file has the same permissions (-r--r-----) but still I can edit it when doing sudo nano. I will used visudo from now on. Also another way to fix it if you have the root password is to simply do 'su' then edit the file. –  user64204 Mar 24 '11 at 9:07
    
@user64204 Interesting... My standard editor (emacs) prevents me from editing the file, while vi makes it very clear it is non-writable but lets me bypass. Another reason to ditch nano ;) –  pehrs Mar 24 '11 at 10:08
    
+1 for visudo. Also, see askubuntu.com/a/73872/5078 for info on using pkexec for recovery (via PolicyKit). –  belacqua May 22 at 22:36

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