0

I stupidly run sudo chown -R pi / and now sudo displays sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

I have only access as user "pi" via SSH. Is there a way to restore it without having access to recovery?

1 Answer 1

1

I'm sorry to be the bearer of bad news, but your system is effectively hosed.

What you did was to change the metadata for each and every single file on the system to the user pi.

Lots of things on Linux systems require specific ownership for things to work as intended, both for technical and security reasons.

Chances are that if you reboot that system in its current state, it won't come back up, or at best it'll come up with lots and lots of errors.

  • Your best choice at this point is likely to restore from a backup taken before you executed the chown command.
  • Your second best choice is likely to rebuild from scratch, possibly copying files on an as-needed basis to the newly installed system.

There are ways to recover, but they involve copying file ownership from another, similar system. Basically, you'd build a list of files, directories and ownership on a known-good system, transfer that to the broken system, and apply it to the broken system. Unless you planned in advance for this contingency, that is likely to, at best, be a laborious process.

1
  • Best thing to do: 1) Make a backup or use a second card. 2) Use a fresh raspbian 3) Restore /home, files from /etc which are probably changed by you and depending on what you did with the pi files in /var (i.e. mysql databases). For /etc most files should be owned by root, in /var you need to take care which services are writing the files. Possibly look at the default files from the reinstalled programs and which user owns them.
    – allo
    Nov 6, 2017 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.