How to Reset Root Password in CentOS, AlmaLinux & Rocky Linux via GRUB

Premium services since 2010

Trusted by thousands of businesses worldwide • 99.9% Uptime Guarantee • Crypto Accepted

Table of Contents

Reset root password in CentOS AlmaLinux Rocky Linux via GRUB emergency shell

Losing or forgetting the root administrative password on your Linux VPS, dedicated server, or CentOS / AlmaLinux instance does not require reinstalling the operating system or losing your valuable data. Using the out-of-band VNC Console, you can boot into the GRUB bootloader emergency shell, chroot into the system root, and reset the root password in less than 5 minutes.

This comprehensive recovery guide applies to CentOS 7, CentOS 8/9 Stream, AlmaLinux 8/9, Rocky Linux 8/9, and RHEL installations.

Step 1: Access the out-of-band VNC Console

Because SSH access requires valid credentials, password recovery must be performed via the server’s virtual monitor:

  1. Log in to the Aminserve Client Area.
  2. Navigate to your active VPS or Dedicated Server management page.
  3. Launch the web-based HTML5 VNC Console (or follow our VNC console guide).

Step 2: Reboot the server and interrupt the GRUB bootloader

  1. From the client portal or VNC menu, click Reboot (or press Ctrl + Alt + Del).
  2. As soon as the server begins booting and the GRUB menu appears, immediately press the Arrow Up or Arrow Down key to pause the boot countdown timer.
  3. Highlight your primary kernel (the top entry) and press e on your keyboard to edit boot parameters.

Step 3: Modify kernel boot arguments (rd.break or init)

  1. Use your arrow keys to scroll down through the configuration lines until you locate the line starting with linux16, linuxefi, or linux.
  2. Move your cursor to the end of this line.
  3. Add a space and append the emergency break parameter:
    rd.break

    (Alternatively, for older CentOS 7 kernels, locate the ro parameter, change it to rw, and append init=/sysroot/bin/sh).

  4. Press Ctrl + X to boot the kernel with your modified arguments.

Step 4: Remount sysroot and chroot into the system

The system will drop you into a switch_root:/# emergency ramdisk shell. Execute the following commands in order:

  1. Remount the target root filesystem in read-write mode:
    mount -o remount,rw /sysroot
  2. Switch root execution context into your installed operating system:
    chroot /sysroot
  3. Your shell prompt will change to sh-5.1# or bash-4.2#.

Step 5: Set the new root password

  1. Execute the password utility:
    passwd root
  2. Type your new secure password and press Enter.
  3. Retype the password to confirm. You will see the confirmation message: “passwd: all authentication tokens updated successfully.”

Step 6: Trigger SELinux autorelabel (Critical)

On RHEL, CentOS, AlmaLinux, and Rocky Linux, SELinux security contexts must be updated for the new shadow file. If you skip this step, SELinux will block root authentication on normal boot:

touch /.autorelabel

Step 7: Exit and reboot to normal mode

  1. Exit the chroot environment:
    exit
  2. Reboot the server:
    reboot

During startup, the system will perform an automated SELinux relabeling process (takes 1–2 minutes) and reboot into the normal login screen. You can now connect via SSH using your new root password.

For high-performance, developer-ready Linux cloud infrastructure with automated snapshots and out-of-band management, explore Aminserve Linux and Windows VPS hosting with 1Gbps ports and 24/7 dedicated support.

Never Miss an Update

Get expert tips, tutorials, and hosting insights delivered to your inbox weekly. Join 10,000+ subscribers!
🔒 We respect your privacy. Unsubscribe anytime.