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
  • Does the system allow ssh-ing in as root? – reinierpost Aug 24 '15 at 18:52
  • Does su work? – Jenny D says Reinstate Monica Aug 25 '15 at 8:46
  • @renierpost: no it doesnt. How do i configure it to? – akshitBhatia Aug 26 '15 at 7:21
  • @JennyD: su does not work. It gives me permission denied. Cannot use sudo. – akshitBhatia Aug 26 '15 at 7:21

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.


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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.