Recover root password for CentOS 8

Estimated reading time: 1 min

Introduction

In this article, we will learn how to reset the forgotten password of root user account on CentOS 8 operating system.

Prerequisites

  1. You should have a VPS, Budget Server, or Dedicated Server with CentOS 8 installed.
  2. You should have access to your Snel client control panel to open a KVM console.

Note: You can not reset the root password using the OpenSSH shell. You must have access to the KVM console of your server to follow along.

Step 1: Open KVM Console

To open a KVM console on for dedicated server or managed dedicated server, please use this article.

To open a KVM console for budget server please use this article.

To open a KVM console for VPS, login to your Snel account and click on your VPS under services.

VPS

Under the VPS service details page, click on Console to open up the KVM console.

Console

You should have the KVM console open in a new browser tab.

KVM Console

Step 2: Reboot Machine

While you have your KVM console open, reboot the server to get the GRUB menu.

Dedicated server users: Open the Server Power Control tab from the service details page of the dedicated server. Click the Reboot button to reboot the server.

Reboot dedicated server

VPS users: Open the service details page of the VPS and click on the Reboot button.

Reboot VPS

Note: After rebooting your server quickly go to the KVM console as GRUB menu waits only a few seconds before booting the OS.

Step 3: Modify Boot Parameters

On KVM console, press e when you see this GRUB screen as shown in the picture.

GRUB

This will open an editor for you to edit the boot commands.

Important: If you missed the grub screen, go ahead and reboot your server again.

Once you are in edit mode, add rd.break enforcing=0 at the end of the line starting with linux as shown in the picture.

Once done, press Ctrl-x to boot with changed parameters.

rd.break breaks the boot process at initramfs and enforcing=0 disables the SELinux.

Step 4: Reset Password

Once the system boots up with the modified command, the switch_root prompt will appear.
Remount the read-only file system /sysroot in write mode by running the following command.

mount -o remount,rw /sysroot

Change shell to file-system’s root by running:

chroot /sysroot

This will change the shell to sh-4.x.
Now, you can change the root password by running the following command.

passwd

change password
Once done, exit to switch_root prompt by running:

exit

Reboot the server by running the reboot command.

Conclusion

In this tutorial, we learned how to reset the password of the root user on CentOS 8 operating system.

Was this article helpful?
Dislike 2
Views: 3817

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *