I broke sudo while installing Zigbee2Mqtt

Recently I tried installing Zigbee2Mqtt next to my openhab2.5
I followed the instructions found here:

But after executing ```
sudo chown -R ${USER}: /opt/zigbee2mqtt
I keep getting following error when trying any sudo command:
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
Solutions I find online are either telling me I need to reinstall my OS, which I definitely want to avoid since I also have other custom code running next to openhab, communicating with my openhab over mqtt. This runs for more than a year now but I remember having a hard time getting it to work. Since I don’t take notes on everything I do, I will also not remember how to get it to work again so I will have to figure everything out once again on a fresh installation. I also can’t backup my openhab since I need to do this with a sudo command…
An alternative solution I find is to login as root but that doesn’t seem to be possible in openhabian…
Does anyone has any idea on how to fix this?

so, since the error msg is quite specific:
what is the current ownership of /usr/bin/sudo ?

ls -la /usr/bin/sudo

-rwxr-xr-x 1 1001 1001 135376 Jan 31 2020 /usr/bin/sudo

Altough if I cat /usr/passwd I can’t find any user with that UID…

that would be /etc/passwd but anyway, when it puts the uid numerical that tells you the OS can’t find a user entry with that uid itself.

On my system it get this:

$ ls -la /usr/bin/sudo
-rwsr-xr-x 1 root root 147560 Jan 20  2021 /usr/bin/sudo

note the s in -rws above, guess it signifys said setuid bit. Google it.

1001 probably existed once, was referenced in an unfortunate chown command, and later deleted.

Did you keep notes of the root passwd on that box? You could try su to become root, then chown root: /usr/bin/sudo

If you don’t know the root password you will need another linux box, for example a virtualbox with a minimum debian install. You would mount the sd-card on that system and fix the permissions as root from there.

Good luck and yes, keeping a journal of your installs and modifications can be really useful. Take a look at ~/.bash_history

And if you want to research your install history on that system, try this:

zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep -Po '^Commandline: apt-get install (?!.*--reinstall)\K.*'

(This is taylored for apt-get, if you used apt instead, modify the search pattern accordingly)

Good luck!

1 Like

I can only recommend in the strongest possible terms to use some kind of tool to manage deployments instead of manually messing around with machines directly. It doesn’t scale, it isn’t reproducible and getting things back to a “known good” configuration is close to impossible.

Right. That’s what openHABian is built for.

Should have mentioned this in my first post.
But I’m actually running openHABian on a raspberry pi.

The problem is there seems to be no root in openHABian?
So I cannot use the ‘su’ command to fix my file system. Or am I missing something?

I’ve had that very same issue with openHABian before as well, so that is not a precaution.

Happened during a Homebridge initiated update, so also not really that much of manual messing.

My only option was to reinstall the system, admittedly with openHABian made easier. I also then set up a root password, disable root login for general use, but enable it before installations where this might possibly appear again so I can easily correct sudo again just in case.

Yes about everything:
You can use sudo <cmd> to execute cmd as root as documented in many places.
You can install zigbee2mqtt from the menu, no need to do that manually.
No backup taken before messing with the system. No regular backup in place.
How to ask a good question / Help Us Help You - Tutorials & Examples - openHAB Community

He cannot. The system is broken e.g. sudo permisions are wrong accoring to post 3 :

I broke sudo in this way recently, and I was able to recover from it without reinstalling. I had to boot my system into rescue mode using grub, then change the ownership of sudo (and half the rest of the drive) back to root. Since my debian install had disabled the root account, I had to set a password for that too.
Once sudo worked again I used apt to reinstall all packages so they fixed their ownerships too.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.