How to reset a root password on VPS with CentOS 7
This guide explains how to reset a lost root password on a server with CentOS 7. The same method with rd.break also works on AlmaLinux and Rocky Linux 8 and 9.
Reset the Root Password on a VPS
Open the VNC console of your server in the client area. If the server is running, restart it with the Send Ctrl+Alt+Del button.
After the BIOS screen, you will see the GRUB boot menu. Use the ↓ and ↑ keys to highlight the kernel you want to boot and press e to edit its boot parameters.
Find the kernel boot line, which starts with linux16 or linux and contains /boot/vmlinuz.
The ro parameter loads the kernel in read-only mode. To be able to save a new password, replace ro with rw init=/sysroot/bin/sh in this line.
Press Ctrl+X (or F10) to boot the system in single-user mode with this setting. When the shell starts, switch to the system root:
chroot /sysrootSet a new root password:
passwd rootEnter the new password twice. If SELinux is enabled, tell the system to relabel files at the next boot, otherwise you will not be able to log in:
touch /.autorelabelSave the changes and reboot:
exit
rebootThe first boot after relabeling can take a few minutes.
Reset the Root Password on a Dedicated Server
In the IPMI web interface, go to Remote Control > Console Redirection and click Launch Console.
Older IPMI versions use a Java console, so you need the Java Runtime Environment. After you click Launch Console, a file is downloaded. Save and open it, then tick the checkbox at the bottom of the dialog and click Run. Modern IPMI interfaces use an HTML5 console that needs no Java.
If you launch the Java console for the first time, Java may block it with a security warning. In that case, add the IPMI address (with both http:// and https://) to the Exception Site List in the Java Control Panel, then start the console again.
When the console is open, restart the server: go to Remote Control > Power Control and choose Reset Server.
After the BIOS screen and before the OS boots, you will see the GRUB menu. Use the ↓ and ↑ keys to choose the kernel and press e to edit it.
Find the line that starts with linux16 on BIOS systems or linuxefi on UEFI systems (on newer systems, linux). Change ro to rw and delete the rhgb and quiet parameters. Then add rd.break enforcing=0 at the end of the line.
Press Ctrl+X to boot the system in single-user mode. Run these commands to change the root password and restart the system:
chroot /sysroot
passwd root
touch /.autorelabel
exit
rebootIf you have any difficulties or questions, contact our support team through the ticket system.
Blog