How can we help you today?
lifebuoy-100

Do you need help with this?

Our team of experts are standing by to assist. Just open a ticket and we'll lend you a hand.

Stay in the know

Enjoy exclusive access to discounts and knowledgeable tips.

We don’t spam! Read our privacy policy for more info.

< All Topics
Print

How to reset root password (RHEL-based distros)

Table of Contents

This process works if you have console access to a VPS or IPMI access to a dedicated server. Please contact support.

Due to the nature of this information, NodeSpace Support will not reset root user access to a server from an account that has not authenticated themselves to our technical support.

This article only applies to Red Hat Enterprise Linux-based distros (RHEL, CentOS, Rocky Linus, AlmaLinux). This process will not work for Debian, Ubuntu, or other distros.

  1. First, you need console access: Either at a keyboard and monitor locally, or via Virtual Machine remote console, you will need to see and interact with the bootloader.
  2. Reboot the machine: As soon as the bootloader comes up with the selection screen, quickly tap the up and down arrows up and down to pause the countdown.
  3. Select the kernel you want to boot into, and hit ‘e‘: This will take you into a screen where you can edit the grub bootloader script.
  4. Find the line that refers to the kernel: There will be a series of ‘boot parameters’ here: these are instructions passed during the loading of the kernel.
    1. For RHEL/CentOS 7, the line starts with ‘linux16‘.
    2. For RHEL/Centos 8x/AlmaLinux/Rocky Linux etc. the line starts with ‘linux‘.
  5. Add ‘rd.break’ at the end of that line (There are other things you can do here, but for now, this is all you need) [ Note: This change is temporary ].
  6. Now hit Ctrl-x to run the edited bootloader script.
  7. You’ll boot to a ‘rescue’ prompt that looks like this: switch_root:/#.
  8. Remount the root partition in read-write mode so that you can run commands. Enter the following: mount -o remount rw /sysroot and then hit ENTER.
  9. Now type chroot /sysroot and hit enter. This will change you into the sysroot (/) directory, and make that your path for executing commands.
  10. Now you can simply change the password for root using the passwd command.
  11. Next, before you reboot, you will need to make sure that SELinux allows the file changes. At the prompt ,enter: touch /.autorelabel. This will signal SELinux on the next reboot that the filesystem has changed (the changed password) and allow the change to be loaded. This will cause the whole filesystem to be ‘relabeled’ which might take a while, depending on the size of the filesystem and the speed of the machine, so be aware of this possibility.
  12. Type exit to leave the chroot environment and enter reboot.