No matter what version of CentOS you are using (or any other Linux distribution), the root user is the most important user of your server. The root user has full access to that particular computer and it is of extreme importance for a sysadmin. Loosing the root user access it’s not just frustrating but can mean loosing access to you files, emails, databases and also being stuck if having to fix an urgent issue internal to your server.

Fortunately, as long as you have console access to your server you may configure a new root password simply by following the steps below (the procedure of resetting the root password it is slightly different for each version of CentOS):

 

 

CentOS 7

  • 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.
  • At the GRUB boot prompt, press E to edit the first boot option.
  • Find the kernel line starting with linux16.
  • Change ro to rw init=/sysroot/bin/sh.
  • Press CTRL+X or F10 to boot into single user mode.
  • Access the system with the command: chroot /sysroot.
  • Type passwd and follow the prompts to change the root password.
  • Run reboot -f to reboot the server.

 

CentOS 8

  • 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.
  • At the GRUB boot prompt, press E to edit the first boot option.
  • Find the kernel line starting with linux.
  • Change ro to rw init=/sysroot/bin/sh
  • Press CTRL+X or F10 to boot into single user mode.
  • Access the system with the command: chroot /sysroot.
  • Type passwd and follow the prompts to change the root password.
  • Run touch /.autorelabel to force file system relabeling.
  • Run exit.
  • Run logout.
  • Run reboot to reboot the server.