0

Believeing I was in another directory I accidentally ran the following command on the root:

sudo chown -R j:root /

My username is j

Unfortunately because of this I am unable to run any sudo commands and undo my mistake, as the server can no longer access the sudo file. I am also unable to login via SSH as the file that controls that is also inaccessible!

I have physical access to the device - Is there a way to undo my mistake?

JBithell
  • 111

1 Answers1

0

There is recovery mode on desktop versions but I don't know whether it exists on sever versions. It can drop a rootshell, so maybe stop reading my answer and check out whether it exists.

If it doesn't, you can chroot into the system if you can boot into a live session. So do the latter and execute these commands:

sudo mount /dev/sdxY /mnt 
sudo mount /dev/sdzY /mnt/boot # THIS LINE ONLY WHEN USING A DEDICATED BOOT PARTITION!!!
sudo mount /dev/sdwY /mnt/boot/efi # THIS LINE ONLY WHEN USING UEFI!!!
sudo mount -t devtmpfs /dev /mnt/dev
sudo mount -t devpts /dev/pts /mnt/dev/pts
sudo mount -t sysfs /sys /mnt/sys
sudo mount -t proc /proc /mnt/proc 
sudo mount -t tmpfs /run /mnt/run 

Replace /dev/sdxY with your system partition, /dev/sdzY with your boot partition, and /dev/sdwY with your efi partition (but why the hell would you be using uefi anyway!?).

And then run sudo chroot /mnt /bin/bash to chroot into the other system. You can exit via exit.

UTF-8
  • 5,710
  • 10
  • 31
  • 67
  • Thank you for your superb answer - In the end I reinstalled the server as it was a new install but hopefully your answer will provide assistance to silly people like me in the future! – JBithell Oct 12 '15 at 18:52