How to reset the root password on CentOS

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

Process overview

  1. Access the VNC Console.
  2. Restart the server and edit kernel boot parameters to boot the server into single-user mode.
  3. Set a new root password without knowing the old one.

Access the VNC Console

  1. Log in to the Customer Portal
  2. Find your server
    • For a cloud server, go to Cloud Servers → Instances.
    • For a bare metal server, go to Enterprise Bare Metal → Manage.
  3. In the server details page, click the VNC Console button.

Edit 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.

Bare metal server

  1. Restart the server using Send CtrlAltDel button in the VNC Console. After the BIOS menu, press ESC to stop the timer and access the GRUB boot menu.

GRUB boot menu on CentOS 6

  1. Use ↓ and ↑ keys to select your boot line and press e to edit.

GRUB entry selection on CentOS 6

  1. Select the line starting with kernel /vmlinuz- and press e again.

Editing kernel parameters in GRUB

  1. Add the single parameter at the end of the line.

Single parameter added to kernel line

  1. Press Enter to save, then press b to boot the server into single-user mode.

Cloud server

  1. Restart the server using Send CtrlAltDel button in the VNC Console. Press Tab to stop the timer and edit the boot menu.

GRUB cloud server boot menu CentOS 6

  1. Remove the highlighted parameters and add 1 (with a leading space) at the end of the string.

Removing parameters from boot line

Modified boot parameters on cloud server

  1. Press Enter to boot the server into single-user mode.

Set a new root password

If the kernel boot parameters were modified successfully, the server boots into single-user mode and displays a prompt similar to switch_root:/#.

passwd root
reboot

On this page