1

A classical error

By mistake we did sudo chown -R ubuntu:www-data / on a ubuntu 20.04 AWS EC2 server. While there are many posts which indicates that I cannot salvage the machine and have to reinstall a new one - I want to take a copy of the postgres that runs on this server. Currently We could not do any command with a sudo. Hence we could not start postgres or login through phppgadmin.

We have done the following:

  1. Stopped the instance
  2. Detached the volume
  3. Created a new instance
  4. Attached the volume
  5. Mounted the volume
  6. Changed to root in the new instance
  7. did chown -R root:root /mnt/rescue (changed this to root:ubuntu, ubuntu:ubuntu, etc)
  8. did chmod -R 4755 /mnt/rescue (also did 0755, ug-s, etc)
  9. Exited root
  10. umount /mnt/rescue
  11. Shut the rescue instance
  12. Detach the volume
  13. Attach the volume to the corrupted machine. The machine indicates the new owner - but sudo not working.
  14. We tried creating a new instance - attaching this corrected volume, updated /etc/fstab - reboot the instance. We got the volume merged with the machine. After reboot - still the same issue - not able to sudo.

We can certainly re-create the machine or take the back up and restore. However, some mission critical data is residing in the postgres. How do I sudo, or retrieve files from a dead postgres.

We are constantly facing the error:

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

however, when I do ls -l anywhere from inside /usr or /usr/bin - the entire ownership of all the file remains with ubuntu:ubuntu or other combinations that we have tried.

6
  • Just copy the files? This is pretty trivial. Jul 29, 2021 at 18:54
  • Which files of postgres?
    – Apricot
    Jul 29, 2021 at 19:05
  • The whole data directory. Jul 29, 2021 at 19:06
  • When I checked for data dir - i got this path /var/lib/postgresql/13/main do you mean this directory?
    – Apricot
    Jul 29, 2021 at 19:11
  • Yes, if that's where your system kept the files, then that's what you want to copy. Jul 29, 2021 at 19:12

1 Answer 1

0

Try setting the setuid bit and make it executable for root, which is the default permission (rws) for sudo

chmod u+s /mnt/rescue/usr/bin/sudo
chmod +x /mnt/rescue/usr/bin/sudo

While this could be useful to resuce the system, there are many other files and directories which have different such permissions and ownerships, and setting them individually can be tedious.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .