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:
- Stopped the instance
- Detached the volume
- Created a new instance
- Attached the volume
- Mounted the volume
- Changed to root in the new instance
- did
chown -R root:root /mnt/rescue
(changed this to root:ubuntu
, ubuntu:ubuntu
, etc)
- did
chmod -R 4755 /mnt/rescue
(also did 0755
, ug-s
, etc)
- Exited root
umount /mnt/rescue
- Shut the rescue instance
- Detach the volume
- Attach the volume to the corrupted machine. The machine indicates the new owner - but sudo not working.
- 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.