Article

Table of Contents
Theme:
Was this article helpful?

8  out of  24 found this helpful

Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

Reset the Root Password on CentOS

Last Updated: Tue, Feb 22, 2022
CentOS System Admin Troubleshooting Guides

Introduction

If you are locked out of your CentOS instance and have lost access to the root account, you need to boot into single-user mode and reset the root password. You'll find instructions below for CentOS 6, 7, 8, 8 Stream, and 9 Stream.

Connect to the Console

  1. Click the Server Restart icon in the Vultr customer portal.

    Server Restart

  2. Open the web console.

    Vultr Web Console

    You can also reboot the server from inside the web console. See the Web Console FAQ for more information.

  3. Follow the steps below for your version.

CentOS 6

  1. As the system boots, GRUB prompts you to press any key to stop the boot process. Press a key quickly; you only have a few seconds. If you miss the prompt, you need to restart the server from the control panel and try again.
  2. At the GRUB prompt, type A to append to the boot command.
  3. Add a space and the text single to the end of the line.
  4. Press ENTER.
  5. The system will boot, and you will see the root prompt.
  6. Type passwd and follow the prompts to change the root password.
  7. Run reboot to reboot the server.

CentOS 7

  1. As the system boots, press ESC to bring up the GRUB boot prompt. The prompt happens early in the boot process. If you miss the prompt, you need to restart the server from the control panel and try again.
  2. At the GRUB boot prompt, press E to edit the first boot option.
  3. Find the kernel line starting with linux16.
  4. Change ro to rw init=/sysroot/bin/sh.
  5. Press CTRL+X or F10 to boot into single user mode.
  6. Access the system with the command: chroot /sysroot.
  7. Type passwd and follow the prompts to change the root password.
  8. Run touch /.autorelabel to force file system relabeling. This is required for systems with SELinux. When you reboot the system, it will relabel the filesystem for SElinux. The reboot may take extra time during this process.
  9. Run exit.
  10. Run reboot -f to reboot the server.

CentOS 8 & CentOS 8 Stream

  1. As the system boots, press ESC to bring up the GRUB boot prompt. The prompt happens early in the boot process. If you miss the prompt, you need to restart the server from the control panel and try again.
  2. At the GRUB boot prompt, press E to edit the first boot option.
  3. Find the kernel line starting with linux.
  4. Change ro to rw init=/sysroot/bin/sh.
  5. Press CTRL+X or F10 to boot into single user mode.
  6. Access the system with the command: chroot /sysroot.
  7. Type passwd and follow the prompts to change the root password.
  8. Run touch /.autorelabel to force file system relabeling. This is required for systems with SELinux. When you reboot the system, it will relabel the filesystem for SElinux. The reboot may take extra time during this process.
  9. Run exit.
  10. Run logout.
  11. Run reboot to reboot the server.

CentOS 9 Stream

  1. As the system boots, press ESC to bring up the GRUB boot prompt. The prompt happens early in the boot process. If you miss the prompt, you need to restart the server from the control panel and try again.
  2. At the GRUB boot prompt, use the arrow keys to highlight one of the rescue kernels and press E to edit the boot options.
  3. Find the kernel line starting with linux.
  4. Change ro to rw init=/sysroot/bin/sh.
  5. Press CTRL+X or F10 to boot into single user mode.
  6. Press ENTER to enter maintenance mode.
  7. Access the system with the command: chroot /sysroot.
  8. Type passwd and follow the prompts to change the root password.
  9. Run touch /.autorelabel to force file system relabeling. This is required for systems with SELinux. When you reboot the system, it will relabel the filesystem for SElinux. The reboot may take extra time during this process.
  10. Run exit.
  11. Run reboot to reboot the server.

Want to contribute?

You could earn up to $600 by adding new articles.