Posts Tagged ‘Single User Mode’

Linux Server Root Password Retrieval

June 11th, 2009

Here’s an recipe for you… Take one Linux server, add a sprinkle of forgetfullness and leave for an amount of time.

Not a standard recipe I know but this is exactly what I just had to deal with (in my defence it wasn’t me that forgot the password). At work we have a server we rarely use running Redhat (or something close) and with a few staff rotations over recent months the root password literally got lost. Due to an upcoming review of hardware, this password was becoming more and more necessary despite us having limited SSH access to the machine.

After asking a friend and some mutual Googling we came across a guide or two which recommended ways to do the task. I was so pleased with the effectiveness of the information presented that I wanted to provide a link to the site I used and summarise the information on my own site.

For those that don’t like reinventing the wheel visit this link. For the rest of you, read on…

I shall briefly go over the method I used which required physical access to the server and Grub boot loader utilisation. The steps are as follows:

  • Reboot the machine/server and keep an eye out for the GRUB screen.
  • When it does appear then quickly press one of the arrow keys as this page often has a 2-5 second time out before assuming you want the default option.
  • Over the default option press ‘e’ to enter edit mode
  • On the following screen select the line referring to the Kernel and press ‘e’ again
  • At the end of the line add the word ’single’ (with a space before it)
  • Press Escape to exit edit mode and then ‘b’ to boot into single user mode.

Once you have single user access you will automatically have Root access to the machine. Simply type ‘passwd’ at the console and type your new password. You can then type ‘reboot’ and allow the machine to boot as normal then login using your new password.

I did this AFTER trying and failing to use the ‘hard’ method detailed on the Linux forum. So a lesson for the future will be to never assume the worst when it comes to Linux, it’s not always that hard :)

I also took the opportunity to add myself to the sudoers file when I was logged into single user mode. This was simply in case I broke the root password and needed to ’sudo su’ after the reboot. Although not essential it will save you another restart if you mistype the password or break something.