loader
image/svg+xml
  • Data centers and network
  • Products and services
  • Industries
  • Support
  • News
  • About us

Knowledge Base

How to reset the root password on CentOS 6 and 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:

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.

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

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

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

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.

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.

The parameters string should look like on the following picture:

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.

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.

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.

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.

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

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