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 you reset it.

Overview

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

Step 1: Access VNC Console

For a cloud server, find your server in Cloud ServersCreate and Manage in the Customer Portal. For a dedicated server, look in Dedicated ServersCreate and Manage. Open the VNC Console using the button of the same name.

Customer Portal server page with VNC Console button

VNC Console window

Step 2: Edit kernel boot parameters

CentOS 6 – Dedicated server

Restart the server by pressing Ctrl+Alt+Del in the VNC Console window. After the BIOS menu, a timer appears — press ESC to stop it and access the GRUB boot menu.

GRUB boot menu on CentOS 6

Use and keys to select your boot line and press e to edit. Select the line starting with kernel /vmlinuz- and press e again.

GRUB entry selection on CentOS 6

Editing kernel parameters in GRUB

Add the single parameter at the end of the line.

Single parameter added to kernel line

Press Enter to save, then press b to start the system in single-user mode.

CentOS 6 – Cloud server

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

GRUB cloud server boot menu CentOS 6

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

Press Enter to boot into single-user mode.

CentOS 7 – Dedicated server

Restart via Ctrl+Alt+Del in VNC. When the GRUB menu appears, select your boot entry and press e to edit.

GRUB menu on CentOS 7

Find the line starting with linux, linux16, or linuxefi (depending on architecture). Change ro to rw, remove rhgb and quiet, and add rd.break enforcing=0 at the end.

CentOS 7 kernel parameters before modification

CentOS 7 kernel parameters after modification

Press Ctrl+X to start the system in single-user mode.

CentOS 7 – Cloud server

Restart via Send CtrlAltDel in VNC. Select your boot entry and press e to edit.

Cloud server GRUB menu CentOS 7

Change ro to rw, remove highlighted parameters, and add rd.break enforcing=0 at the end.

Before removing parameters on CentOS 7 cloud

After modifying parameters on CentOS 7 cloud

Press Ctrl+X. The system will start in single-user mode.

Step 3: Set a new root password

CentOS 6

passwd root
reboot

CentOS 7

chroot /sysroot
passwd root
touch /.autorelabel
exit
reboot

On this page