4

I need to enter recovery mode of my redhat box which is running remotely on a virtual machine.

I use RedHat 5 64-bit Enterprise Edition.

I am logged into the box using SSH. I can restart using the restart command but I need to know if I will be able to SSH to it, since I am using it remotely and cannot login through the UI.

The real problem is, I had done a chown -R $USER / on the root directory.

I was trying this as a trial not realizing the consequences, to make something work, which somehow was not working even with the use of sudo.

I killed it mid way. But, because of this stupidity, I can't use sudo.

I have read that I can do something in rescue mode, but I don't understand how do I get into rescue mode remotely. I cannot reinstall linux, that is not a possible option.

Is there anyway I can get back my sudo permissions?

Doing this does not work as of now:

chown root:root /usr/bin/sudo
chown: changing ownership of `/usr/bin/sudo': Operation not permitted
sudo chown root:root /usr/bin/sudo
sudo: must be setuid root
peterh
  • 4,953
  • 13
  • 30
  • 44
akshitBhatia
  • 141
  • 1
  • 2

3 Answers3

9

You can't ssh into recovery mode as ssh won't be running. You need a way to get on to console. If this is a virtual machine and you own the host there should be some way to connect to the host and get on console. If this is a service like AWS then you are out of luck and you need to recover it someway else like building a new instance and detaching the root volume from the bad instance and mounting it on the new one to fix it.

Mike
  • 22,310
  • 7
  • 56
  • 79
0

Redhat uses Systemd for starting/stopping jobs.

If you are in rescue mode, it uses the rescue or emergency targets.

You need to config sshd (and its dependencies) to run also on these runlevels (= targets, in the systemd terminology).

Here you can find more about systemd finetuning. Some Redhat docs may be also usable.

peterh
  • 4,953
  • 13
  • 30
  • 44
0

The issue has been solved and this question can be closed. However, i was not able to do this via ssh. I had to turn off the instance on the virtual box and reboot it. Doing this via ssh remains open for discussion.

How to solve the issue by rebooting the rhel5 instance:

1.Boot the system into single user mode (do this by pressing esc on the boot screen. you will get a terminal on the boot screen after doing this)
2.do chmod 0440 /etc/sudoers
Which should look like -r--r----- 1 root root 5882 Nov 19 18:03 /etc/sudoers
3.chown root:root /usr/bin/sudo
4.chmod 4111 /usr/bin/sudo
5.chmod 0440 /etc/sudoers
6.chmod 0770 /var/bin/sudo/$USERNAME (note: you may have to use /var/run/sudo/$USERNAME if /var/bin does not exist)
7.Reboot the machine in runlevel-5. (type init 5)

This will setuid to root and resolves the sudo error

akshitBhatia
  • 141
  • 1
  • 2