Reset Root

Reset root password on RHEL 6 Systems

Reset Root Passwords for RHEL 6, CentOS 6 (method 1)

If you have forgotten your root password on a Red Hat Enterprise Linux 6.x based server or a CentOS 6.x based server, you can reset your root password in several different ways providing you have access to the server. The process of changing/resetting the root password involves either booting into single user mode or booting into rescue mode. Both of these options are described below. In the examples below, RHEL 6.3 was used.

(Note: If you are using a RHEL 7 based system, you will need to use the RHEL 7 reset root password guide).

Booting into Single User Mode - runlevel 1

The easiest method of resetting a lost root password is to boot your system into "Single User Mode" and simply issue the "passwd" command. In Single User Mode, your system will boot to what is known as "runlevel 1". Your local file systems will be mounted, however, your network interfaces will not be activated. Once in Single User Mode, you will have access to a shell prompt where you can reset your root password. Unlike rescue mode, Single User Mode will automatically attempt to mount your file system. Below is a step by step guide to resetting the root password.

Boot your system

To access Single User Mode, you will need to boot your system to the "GRUB" bootloader menu screen. Here you will then be able to add additional parameters to the kernel boot parameter line.

As your system starts to boot, you will need to press the "Escape" key to access the GRUB menu screen:

RHEL 6 GRUB Menu Screen

From this initial menu, highlight your operating system using the arrow keys. At this screen you are presented with various options. Now press "e" to edit.

RHEL 6 GRUB Menu Screen

Now highlight the line starting "kernel" and press "e" again to edit the highlighted parameter.

Once you press "e" you will be taken to the end of the line. Here you will need to press the "space" key and then add the number "1" to the end of the line as per image below.

RHEL 6 GRUB Menu Screen

Now press "Enter" to accept your entry. You will be taken back to the previous screen.

RHEL 6 Change boot kernel parameter

Now press "b" to boot your system.

Your system should now boot into "Single User Mode"

RHEL 6 Single User Mode

At the command prompt you can issue the command "passwd" to change the root account password.

RHEL 6 Change root password

Now reboot your system by issuing the "reboot" command.

Your system will now reboot normally back to its normal runlevel.

RHEL 6 reboot commands

Booting into Rescue Mode (method 2)

Rescue Mode will give you the ability to boot your server from bootable installation media such as an iso image, CD or DVD instead of the system's Hard Drive. You would normally use "Rescue Mode" when you have a system that needs to boot from an alternative boot device due to issues encountered at boot time. Rescue Mode gives you the ability to boot and access/edit files that are stored on the system's hard drive.

To boot your system into "Rescue Mode", you must be able to boot your system by one of the following methods:

Boot by using a CD ROM or DVD.
Boot from an USB device.

Once you have booted your system by one of the above methods, you will need to select the option "Rescue Installed System"

RHEL 6 Boot Rescue Mode

Select Language

Select the Language to use during Rescue Mode. In this example, English has been chosen.

RHEL 6 Boot Rescue Mode Select Language

Select Keyboard Type

Select the Keyboard type you are currently using. In the example a UK keyboard has been selected.

RHEL 6 Boot Rescue Mode Select Keyboard

What type of Media Contains your Rescue Image?

At this point, you must provide media that contains the rescue image. In this example we are booting from an installation DVD, so we have chosen "Local CD/DVD". Choose the option that matches your boot media.

RHEL 6 Boot Rescue Mode Select Recovery Media

Set up Networking

Networking is not needed for a root password reset. To continue without Networking select the option "No". If you do choose the option "Yes", you will be asked to manually define your network settings or use a DHCP server for a leased IP address. In this example we will choose the option of No network.

RHEL 6 Boot Rescue Mode Select Networking

Rescue Environment

The rescue environment will now attempt to locate your Linux installation and mount this at the mount point "/mnt/sysimage".

RHEL 6 Boot Rescue Environment

Rescue Environment Continued

Your system is now mounted under "/mnt/sysimage". Click "OK" to start a shell.

RHEL 6 Boot Rescue Environment

Start Shell

Select the option "Shell Start Shell". Then click "OK".

RHEL 6 Boot Rescue Mode Start a recovery Shell


You should now arrived at a command prompt. In the example this is identified as "bash-4.1#"

RHEL 6 Boot Rescue Mode Shell prompt

chroot shell

To switch this environment to make it your root environment issue the command: chroot /mnt/sysimage
Your prompt will now change to "sh-4#".

RHEL 6 Rescue Mode chroot environment

Look at mounted Filesystems

To confirm your system is mounted, you can issue the command "df -hT".

RHEL 6 Rescue Mode display mounted filesystems

Reset Password for Root

Now to reset the root password you need to type the command passwd root

Now provide the new password for the root account.

RHEL 6 Rescue Mode Reset root password


To exit out of the rescue shell environments you will need to type "exit" twice. This will then take you to a reboot screen.

RHEL 6 Rescue Mode Exiting shell environments

Remove Media

At this point, you will need to remove the bootable media you booted into Rescue Mode with as you are going to reboot the system from the system's hard drive.

RHEL 6 Boot Rescue Mode remove recovery Media

System Reboots - SELinux Relabel

The system will now boot, you will see various messages possibly including a SELinux relabel message. SELinux needs to carry out a relabel as the system was booted using a rescue kernel.

RHEL 6 reboot

Login with New Password

You should now have arrived at the login screen. Here you will be able to login with your root account using your new password. (You may need to login as a normal user then "su" to root depending on your system set-up)

RHEL 6 login new root password