Back

Linux administration

How to reset the root password on CentOS 6 and CentOS 7

  • Password reset algorithm at a glance
  • 1. Accessing VNC console
  • 2. Restarting the server and editing kernel boot parameters
    • 2.1. CentOS 6, Dedicated server
    • 2.2. CentOS 6, Cloud server
    • 2.3. CentOS 7, Dedicated server
    • 2.3. CentOS 7, Cloud server
  • 3. Setting a new root password
    • 3.1 CentOS 6
    • 3.2 CentOS 7

If you have lost the root password of your server, this article will help.

Password reset algorithm at a glance

  • Access the VNC console

  • Restart the server and edit kernel boot parameters to boot into the single-user mode

  • Set a new root password without the old password required

1. Accessing VNC console

This step is the same for all varieties of Linux. For a cloud server, find your server in the "Cloud Servers > Create and Manage" section of the Customer Portal. For a dedicated server, look in the "Dedicated Servers > Create and Manage", respectively. Open VNC Console using the button of the same name:

How to reset the root password on CentOS 6 and CentOS 7
How to reset the root password on CentOS 6 and CentOS 7

Look of VNC Console window may vary depending on the server type and OS.

2. Restarting the server and editing kernel boot parameters

To boot the server into single-user mode, you need to edit kernel boot parameters using the GRUB bootloader menu. Menu behavior and boot parameters depend on OS version and whether it's a bare metal server or a cloud server.

2.1. CentOS 6, Dedicated server

Restart the server by pressing CTRL + ALT + DEL in the VNC Console window.

After the BIOS menu, before the OS starts, a timer appears. Press ESC to stop the timer and access the GRUB boot menu.

How to reset the root password on CentOS 6 and CentOS 7

Use the ↓ and ↑ keys to navigate through the menu. Select your boot line and press "e" to edit it.

How to reset the root password on CentOS 6 and CentOS 7

Select the line that starts with "kernel /vmlinuz- ". Press "e" to edit it.

How to reset the root password on CentOS 6 and CentOS 7

Add the "single" parameter after the space at the end of the line.

How to reset the root password on CentOS 6 and CentOS 7

Press ENTER to save changes. Changes will persist until next boot. Press "b" to start the system in the single-user mode.

Proceed to the "Setting a new root password" section of this article.

2.2. CentOS 6, Cloud server

Restart the server using "Send CtrlAltDel" button in the VNC Console window. While restarting, the boot menu with a timer will appear right after the BIOS menu.

Press TAB to stop the timer and edit the boot menu. Changes will persist until next boot.

How to reset the root password on CentOS 6 and CentOS 7

Remove the parameters highlighted in red on the picture below. Add "1" (without surrounding quotes and with a leading space) at the end of the string.

How to reset the root password on CentOS 6 and CentOS 7

The parameters string should look like on the following picture:

How to reset the root password on CentOS 6 and CentOS 7

Press Enter to boot into single-user mode with these parameters. Proceed to the "Setting a new root password" section of this article.

2.3. CentOS 7, Dedicated server

Restart the server by pressing CTRL + ALT + DEL in the VNC console. After the BIOS menu, before the OS starts, GRUB menu appears.

How to reset the root password on CentOS 6 and CentOS 7

Use the ↓ and ↑ keys to navigate through the menu, select your boot line and press "e" to edit it.

Scroll to the line that starts with "linux" in 64-Bit IBM Power Series or "linux16" in x86-64 BIOS-based systems, or "linuxefi" in the UEFI systems. Change the "ro" parameter to "rw", delete "rhgb" and "quiet" parameters; add "rd.break enforcing=0" at the end of the line.

How to reset the root password on CentOS 6 and CentOS 7
How to reset the root password on CentOS 6 and CentOS 7

Press CTRL+X to start the system in the single-user mode. Proceed to the "Setting a new root password" section of this article.

2.3. CentOS 7, Cloud server

Restart the server using "Send CtrlAltDel" button in the VNC Console window. After the BIOS menu, before the OS starts, GRUB menu appears.

Use the ↓ and ↑ keys to navigate through the menu, select your boot line and press "e" to edit it.

How to reset the root password on CentOS 6 and CentOS 7

Scroll to the line that starts with "linux" in 64-Bit IBM Power Series, "linux16" in x86-64 BIOS-based systems, "linuxefi" in the UEFI systems.

Change the "ro" parameter to "rw", remove the parameters highlighted in red on the picture below.

How to reset the root password on CentOS 6 and CentOS 7

Add "rd.break enforcing=0" at the end of the line. The parameters string should look like on the following picture:

How to reset the root password on CentOS 6 and CentOS 7

Press CTRL+X. The system will start in the single-user mode. Proceed to the "Setting a new root password" section of this article.

3. Setting a new root password

In the single-user mode you have a root console where you should run the following commands to change root password and reboot:

3.1 CentOS 6

passwd root
  reboot

3.2 CentOS 7

chroot /sysroot
  passwd root
  touch /.autorelabel
  exit
  reboot

Share

Suggested Articles

  • Linux administration

    How to reset root password on Ubuntu 16.04 Cloud Server

  • Linux administration

    How to reset the root password on Ubuntu 16.04 on a dedicated server