Learn how to address inhibitors to cloud adoption, recognize data challenges in the cloud and seamlessly move data in the cloud with this FREE EBOOK!!.

Tuesday, 13 November 2012

Reset forgotten Linux Root Password

1. Introduction

The following steps were done on a CentOS 6.3 OS, however the same can be replicated with few modifications on almost all Linux distributions.

If you run lilo boot loader instead of grub you can use the same
method but with some modifications on how to edit lilo boot prompt.

2. Edit Grub boot menu options

First you need to get into grub menu options. This menu is displayed
right at the beginning of the boot. If you cannot see your grub menu
options press "ESC' key.

You should get something similar to this:

Grub Boot Option

Now we attempt to edit grub's boot option. Press "e" to edit the first grub menu option and navigate to kernel line:

Editing the Grub Boot loader

Press "e" key again to edit and remove:

quiet splash

and add:

init=/bin/bash

You may have some different boot options but the main part you need
to change/ add is init=/bin/bash. You will get something similar to this:

Editing the Grub Boot Loader

Once you have edited the line, simply press "enter key" to return to the Grub Boot menu as shown.

Grub Boot menu

At this point, we have edited grub boot menu, and we are ready to boot. Press "b" key to boot.

3. Remount / and /proc

After successfully boot you will be presented with bash command prompt:

bash command prompt

On some linux systems, you will need to completely mount / and /proc partitions. To do that, enter following commands:

# mount -o remount,rw /

# mount -o remount,rw /proc

NOTE: If you are not sure that if your partition is already mounted
RW, run the above command anyway as, otherwise on some systems you
will not be able reset your root password. If you fail to do so, you get
this error displayed on the screen:

passwd: Authentication token lock busy

NOTE: On some Linux distributions, you will have /proc mounted already if this is not your case, just run following command:

# mount /proc

Remounting the / and /proc filesystem

4. reset / recover forgotten Linux root password

To reset a actual root password is now simple as typing :

# passwd

Changing the password for root

5. Reboot

Before you reboot it is recommended but not compulsory to run:

# sync

That's it !! You have now successfully changed the root password of your Linux system.Stay tuned to more such how-to tutorials coming your way shortly !!

Tutorial/ How-To Guide Request

Disclaimer

The following is the opinion of the writer and is not intended to malign any religion, ethnic group, club, organization, company, or individual. The views of the writer are his own, and do not in any way reflect the views of the site they are posted on, other sites affiliated with this site, the staff involved with the site, or any other members of this site.