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