Score:1

Not able to sudo - ubuntu 20.04

ma flag

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.

Michael Hampton avatar
cz flag
Just copy the files? This is pretty trivial.
Apricot avatar
ma flag
Which files of postgres?
Michael Hampton avatar
cz flag
The whole data directory.
Apricot avatar
ma flag
When I checked for data dir - i got this path `/var/lib/postgresql/13/main` do you mean this directory?
Michael Hampton avatar
cz flag
Yes, if that's where your system kept the files, then that's what you want to copy.
Apricot avatar
ma flag
Many thanks...I will try this one and post the response.
Score:0
us flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.