LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   removed myself from sudoers list (https://www.linuxquestions.org/questions/linux-newbie-8/removed-myself-from-sudoers-list-918940/)

faizlo 12-15-2011 02:48 PM

removed myself from sudoers list
 
Hi,

This does not seem to be my day. For some reason (mostly experimenting) I used sudo visudo and removed my name (the whole line) from there. Now, of course, I cannot use sudo any more. I cannot even use "sudo su" to be root. The whole system is unaccessible to me now.

I followed this link:
http://www.psychocats.net/ubuntu/sudo

but I could not use 'sudo visudo' from the root command line. It said root is not in the sudoers file. This incident will be reported.

I don't get this, how can root be not in the sudoers list?
Any solution(s) to this issue?

thesnow 12-15-2011 03:30 PM

You could boot into single-user mode which should drop you in as root to run visudo, or you could boot with a live CD, then mount the disk partition and edit /etc/sudoers manually (if the first way doesn't work).

joeldavis 12-15-2011 05:02 PM

Quote:

Originally Posted by faizlo (Post 4550933)
Hi,
I don't get this, how can root be not in the sudoers list?

Because the function of sudo is to execute things with root permissions so it doesn't make sense to use sudo something when (as far as unix permissions go) you have full control. IIRC most sudoers files are still marked as nonwritable even by root, but root can still force the issue (because it's root) in vim by using the ":w!" command.

faizlo 12-15-2011 05:45 PM

visudo by itself did not work. It said root is not allowed to change it!
I will try the live-CD solution once I find it.

joeldavis 12-16-2011 09:03 AM

yes /etc/sudoers is usually not writable by anyone but since you're root you can for the issue in vi by just adding an exclamation point.

faizlo 12-16-2011 10:25 AM

Will here is what I did:

booted to the recovery mode, and then dropped to the root command. When I typed "visudoers" it said I cannot edit this file (yes, root cannot edit the file).

Then I went to vi, I typed "vi /etc/susdoers" and I was greeted with an empty file. Changed to edit mode, (pressed i) and was giving a warning; E303: Unable to open swap file for "/etc/sudoers", recovery impossible!
I typed my info any way, "faizlo ALL=(ALL) ALL" - without the quotes, and I could not save the file with :w!. Emacs had the same luck (of course!)

Well, any ideas!?

PS. I don't have the live-CD because I keep updating my box 2 months after each release!

faizlo 12-16-2011 10:40 AM

Solved.

I found an old live-CD (10.04) and out of nothing else to do to save my system, I used it (after all, it should give me some way to mount my system partition) following some windows I asked for a root command which I used to "vi" my file.

All seems fine now.

Thanks guys.


All times are GMT -5. The time now is 06:29 AM.