Root Password Reset (CentOS)

Root Password Reset (CentOS)

If you have forgotten the root password and are using the CentOS operating system, you can follow the steps below to reset the password:

  1. Restart the System:

   As the first step, reboot or start the system.

  1. Access the GRUB Boot Screen:

   You’ll need to access the GRUB boot screen during the normal boot process of CentOS. If it doesn’t automatically switch to the GRUB screen, press any key during the system’s startup. Then, press “e” to enter editing mode.

  1. Edit the Kernel Line:

   In the editing mode, locate the “kernel” line, which usually starts with “linux” or “linux16.” Once you find this line, change “ro” (read-only) to “rw” (read-write).  After rw add init=/sysroot/bin/sh

Note: Values such as “vmlinuz-4.18.0-80.el8.x86_64” and “UUID=abcdef” may vary depending on your system configuration.

  1. Save Edits and Exit:

   After making the edits, exit the editing mode by pressing “Ctrl+X” or “F10” on your keyboard. This will boot the system in single-user mode.

  1. Log in as the Root User:

   When the system starts in single-user mode, you can log in as the root user without requiring a password. Inside shell, type chroot /sysroot and press enter.

  1. Change the Password:

   To set a new root password, use the following command:

passwd

   When you run this command, enter the new password and confirm it.

  1. Review SELinux Status (Optional):

   If SELinux is active on your CentOS system, you may need to adjust the SELinux context after changing the password.

  1. Restart the System:

   After successfully changing the password, reboot the system using the `reboot` command.

You can now access the CentOS system with your new root password. We recommend that you choose a safe and complex password and keep it safe.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.