[SOLVED] Set back permissions /etc/sudoers

Who can help me out, tried to fix it with google but I can’t figure it out.

I tried to install the backup-restore program Amanda, during the installation it asked me for a location to put the files on. Wanted to create a folder somewhere but accidentally pressed enter after /etc/.
So this folder is pretty loaded now, but the biggest problem is that I’m unable to execute sudo anymore.

When I try to execute it, it response:

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

I read that the command:
pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
Should restore the permission, but it is asking me for the root password, they say that that user is disabled in OpenHABian, so I can’t run it…

Any ideas are welcome.

You will need to change this through a another GNU/Linux System.

Do you have another GNU/Linux system?
Are you using a raspberry? If yes, do you have a second SD card and a USB-SD card reader?

You could setup a GNU/Linux System for raspberry, start this system, mount the damaged SD card and change the ownership.

You could also setup a VM with e.g. debian to do this from a windows machine.

Of course, it is very likely that the setup damaged much more file permissions, so I guess the best option is to setup a completely new system.

And now learn /etc/ was designed for system configurations, not for backup data :wink:

Thanks for the quick reply, if I setup a new OpenHABian system, is it possible to export my current configuration of openhab, influxdb and grafana etc.?

Hehe I’m glad I didn’t had a real big config yet :sweat:

You could either re-image with OpenHabian or image with Raspbian Lite & install OpenHabian. That’s what I am trying now. I have a root user too :wink:

And if I use the backup script from: Backup/Restore scripts for Linux and MacOS

Re-image ophabian, restore the files by the script, will that work? Or will it backup the /etc/sudoers with permission whiting the backup?

I just checked a backup I ran last night. No sudoers file.

The backup is done via

openhab-cli backup [filename]

where filename is optional, and

openhab-cli restore filename

where filename is mandatory (well, guess why… :wink: )

See https://www.openhab.org/docs/installation/linux.html#command-line-interface-cli for details.

As this backup scripts are especially for openHAB, they will only backup and restore openHAB specific data (i.e. config and persisted data - if stored in $USER_DATA, e.g. MapDB and rrd4j, but not InfluxDB or MsSQL)

Thanks for the quick replies, to execute command openhab-cli you still need to have the sudo right. So I figured that I first need to fix this so I can backup, I have a MacBook (that is linux based) but after trying and reading online, it seems to only mount the boot partition and not the root from a this kind of OS on a SD card.

After some attempts with virtualbox with ubuntu I decided that it will probably work a lot faster if I externally connect the SD card with my other Pi.

But I don’t have a usb card reader for a SD card, will buy that today and try again. Will let it know if it worked :wink:

Will try to export the configs for influxdb and grafana separately.

If you are root you should be able to backup as root. That is basically what sudo does anyway.

Yea I was able to restore the sudo permissions with command

pkexec chown root:root /media/pi/rootfs/etc/sudoers /media/pi/rootfs/etc/sudoers.d -R

so I was able to make a backup!! Hooray!! It even backed up my /etc/openhab2/persistence/influxdb.persist file :slight_smile:
After that I reinstalled Grafana because that wasn’t starting anymore, it still had all the configs I made so I could also make a backup of my dashboard there.

When I got all the files backup’ed and save, I re-imaged OpenHAB. The restore was also successfully after that, when that was done I only had to re-install InfluxDB and Grafana and did some small configs but the most files could be replaced with my older ones.

Everything is working as before, thanks a lot!

1 Like

Sure. But this is only configuration but not data :slight_smile:

influxdb data is spread in many little files in a folder /opt/influxdb/shared (by default) and these files get lost.

2 Likes

@Udo_Hartmann ah ok, that’s good to know. Maybe it’s better then to buy another SD card and make a exact copy/clone if your configuration is finished, if something goed wrong you just swap card and you’re good to go again :slight_smile:

You can backup influxdb data, but you have to use its own backup solution.