[SOLVED] By mistake I deleted a symbol from sudoers


(Juan) #1

Hi there,

I am using openhabian. By mistake I deleted a symbl % in the sudoers and now I can not use sudo anymore, I get the message that “openhabian is not in the sudoers file. This incident will be reported.”

Is it possible to solve my mistake? :disappointed_relieved:


(anonymous.one) #2

You may have to leverage the grub boot manager and boot into single mode (dumps you in as root) and you should be able to add the openhabian user back into the file.


(Juan) #3

how I run the grub boot manager?

EDIT: https://www.tecmint.com/fix-user-is-not-in-the-sudoers-file-the-incident-will-be-reported-ubuntu/

Not working with shift key to enter in grub boot manager :confused:


(Rich Koshak) #4

It’s too late for your but for future readers of this post… Never ever ever edit the sudoers file except by using

sudo visudo

visudo will parse and verify that the sudoer’s file is syntactically correct before applying the changes. Without this any mistake you may make will make it impossible to sudo on the machine.

I don’t think grub is available on Raspbian. I’ve never seen it pop up or seen a way to get into it.

@grhosso, this is an old thread but it might work. Plug the SD card into another machine and edit /boot/cmdline.txt as described in that thread. You will need to have the RPi plugged into a keyboard and monitor when you boot next.

Once done you will have a shell running as root and you can edit the sudoers (use visudo please).

If that doesn’t work, you will need to mount the SD card on some other computer that can read ext2 filesystems and edit the file from there.


(Juan) #5

no luck… :confused:


(anonymous.one) #6

Doh, I read raspberry and openhabian and my brain still translated as debian/ubuntu distro!

@grhosso Since you probably have to put the SD card into another system, it will probably be easier to mount the card in a VM running some linux distro and fix the file.

Another option is to grab a backup of all your openhab folders in /etc (logs/graphs if you need them), and any other application configs you may have on there and re-install from scratch; and chuck this up to a life lesson.


(Udo Hartmann) #7

You don’t need to use some hacks, as it’s a debian system (and not ubuntu), you can simply

  • login, then use
  • su - to become root and afterwards use
  • visudo to edit the file.

Of course, you have to know what the file has to look like, as visudo won’t let you save the file when it’s corrupt, but will not “repair” a faulty line for you.


(Juan) #8

I tried that and but I got:

su: Authentication failure

I have edited the file in other computer in my work, this evening I will see if is working.
Thanks.


(Rich Koshak) #9

Root is disabled on raspbian and has no password. You can’t su to root without using sudo. All privilege elevation goes through sudo so to become root you would need to sudo su - at which point you may as well just put the command you want to run or sudo /bin/bash to get a root shell.

In this respect it is more like Ubuntu than Debian.


(Juan) #10

ok, I could modify the file sudoers from Ubuntu machine. Very easy. ufff I saved everything.

Thank you!


(Udo Hartmann) #11

Oh, I wasn’t aware of this point (and I have quite a few Raspberrys…) …my bad.