Help - I did sudo chown -R openhabian /etc

sudo chown -R openhabian /etc was not so smart, I guess.

Why id did it? I added the samba srv config to share /etc
I wanted to be able to change the config files in /etc directly over the share (Visual Studio Code is great for editing config files), without opening the terminal an using the annoying nano editor.

Result:
I can’t do any sudo any more. I each time get the complaint:

sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

So I should try to make root owner again of /etc/sudoers. How?

I could try to run as root, or just type “su”, but these users are, as far as I know, disabled op OpenHABIANPI.

Who can help me?

What I cannot do:

  • I cannot do chown root /etc/sudoers (permissions denied)
  • I cannot do “sudo chown root /etc/sudoers” (as I cannot sudo any more)
  • I edited cmdline.txt, by adding init=/bin/sh and then boot in single user mode: the problem is then that the disk is in read-only mode (I cannot edit files). When doing
    mount -o remount,rw /
    I get an issue that the PARTUUID=2F93…b not found (that is afaik the equivalent of te non-boot partition on the sd-card).

I have no more inspiration…

Any tips?
tx!!!

:see_no_evil:

Did you try rw init=/bin/sh instead?

thanks for the tip, @Benjy - I 'll give it a try tomorrow and let you know the result.

From a quick search:

AS ROOT:

chown root:root /etc/sudoers
chmod 440 /etc/sudoers

i would add the two lines from @vzorglub at the end, but before exit 0, in etc/rc.local

after a reboot, the file should have the right group and rights again and you can undo the changes in etc/rc.local

@vzorglub & @mueslee thanks for these suggestions. I will try the next scenario:

  1. shutdown the raspberry, take the SDcard out and add to /boot/cmdline.txt
rw init=/bin/sh
  1. I didn’t know rc.local, and did some research. this info is in rc.local:

This script is executed at the end of each multiuser runlevel.

cmdline.txt makes me boot in single user mode - I am not sure, but it sounds like a contradition. I derive that I will first not add commands to this script, but rather I will run them manually & directly on the raspberry (not over ssh). If that doesn’t work, I can try it with rc.local.

  1. Boot (single mode level is always as root):
    run:
chown root:root /etc/sudoers
chmod 440 /etc/sudoers
  • shutdown the raspberry
  1. Set the original cmdline.txt back and reboot.

Hope this helps - I will keep you posted on the results.
Many regards, Peter

Great news: it worked the way described above in my last post (using rw init=/bin/sh to cmdline.txt )
I did it the manual way as descibed (=without rc.local), but that is not the most essential, I guess.
I now can smoothly sudo again :slight_smile:

Thanks to you all folks, I can be proud of this experience & learning. All my appreciations!

Happy OpenHAB to all of you!

*** POST-LEARNINGS ***
I now can sudo, but I get another error msg:

sudo: /etc/sudoers.d is owned by uid 1000, should be 0

I fixed by:

sudo chown -R root:root /etc/sudoers.d
sudo chmod -R 755 /etc/sudoers.d

Thanks for this post Peter, I made exactly the same stupid mistake and have been googling for hours before I found this post. I was ready to give up on this installation, but your post got my openhabian in perfect shape again! Thanx again, Robl