Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to reset the root password on CentOS or RHEL 7

This guide shows you how to set a new root password if you forgot it. You need console access to the server, so it is for VPS and dedicated server customers.

How-To Guides2 min read12 steps4 screenshots

What is the root password?

Root is the main administrator account on a Linux server. It can do everything. The root password is the key to that account.

To reset it, you restart the server and tell it to start in a special rescue mode. In this mode, you can change the password without knowing the old one. You must be able to see and type in the server's screen. This is called the console. Your VPS panel or Hostvento support can tell you how to reach it.

Tip: CentOS 7 and RHEL 7 are old. Newer versions work in a similar way, but small details may differ.

Before you start

This needs a restart, so your sites will be offline for a short time. Pick a quiet moment. Take a backup or snapshot if your plan allows it.

Steps

  1. Open the console of your server and restart it. Use the reboot button in your panel, or choose Send Ctrl+Alt+Del.
  2. When the boot menu (GRUB) appears, quickly press the e key. This lets you edit the start-up settings.
    Grub Edit Mode
  3. Use the arrow keys to find the line that starts with linux16 (or linuxefi).
  4. Go to the end of that line. Remove any words rhgb quiet if they are there.
  5. Add this at the end of the line:
    rd.break to kernel
rd.break enforcing=0

rd.break stops the start-up early. enforcing=0 turns off the SELinux safety check for this boot only.

  1. Press Ctrl and X to start with these settings.
  2. When you get a prompt, make the disk writable:
mount -o remount,rw /sysroot
  1. Switch into the real system:
    System Reboot
chroot /sysroot

This makes the next commands act on your real server files.

  1. Set the new password:
passwd root

Type the new password twice. You will not see it on screen.

  1. Tell the system to fix its safety labels on the next start:
touch /.autorelabel
  1. Leave the rescue shell and restart:
exit
exit

The server restarts. The first start may take longer while it fixes the labels. Do not turn it off.

  1. Log in as root with the new password.
    Resetting Root Password
Warning: If you skip the touch /.autorelabel step, you may be unable to log in. Pick a strong password and keep it somewhere safe.

If you cannot reach the GRUB menu, open a ticket with Hostvento support at the support ticket page.

Quick recap

  • Restart the server from the console and press e at the boot menu.
  • Add rd.break enforcing=0 to the linux16 line.
  • Remount, chroot, then run passwd root.
  • Run touch /.autorelabel and exit twice.
  • Log in with the new password.