Reset root password using single user mode in Linux

It is possible that you loss or forget your root password for your Linux server and you do not have sudo user as well. In such case, you can reset your root user password by booting your server in single user mode. The steps may vary depending on your Linux operating system.

WHMCS Complete Billing and Support

We will provide steps for different Linux operating systems to reset root password using single user mode. Before you proceed, kindly make sure that you have direct console access for your server (via KVM or other way) or direct physical access.

[1] CentOS 6

  • Restart your server using console or other available options.
  • You will see a GRUB boot prompt telling you to press any key. You have only a few seconds to press a key to stop the automated booting process. If you miss, you will have to reboot your server again.
  • At the GRUB prompt, type “a” to append to the boot command.
  • Add the text “single” and press enter.
  • System will boot and you will see the root prompt. Use passwd command to change the root password and then reboot again.

[2] CentOS 7

  • Restart your server using console or other available options.
  • As soon as the boot process starts, press ESC to bring up the GRUB boot prompt.
  • You will see a GRUB boot prompt – press “e” to edit the first boot option. (If you do not see the GRUB prompt, you may need to press any key to bring it up before the machine boots).
  • Find the kernel line (starts with “linux16”), change ro to rw init=/sysroot/bin/sh
  • Press CTRL+X to boot single user mode.
  • Run passwd command to change the root password.
Posted in Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *