How To Reset Your Forgotten Root Password On CentOS/Ubuntu Servers

CentOS 6

Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.

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 this prompt you will need to restart the VM 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. Type "passwd" to change the root-password and then reboot again.

CentOS 7

Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.

As soon as the boot process starts, press ESC to bring up the GRUB boot prompt. You may need to turn the system off from the control panel and then back on to reach 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 or F10 to boot single user mode.

Access the system with the command: chroot /sysroot.

Run passwd to change the root password.

You’ll be prompted to create and confirm a new password.  After creating the password, run the commands below to update SELinux parameters
touch /.autorelabel

Reboot the system: reboot -f.

Debian, Ubuntu

Click [View Console] to access the console and click the send CTRL+ALT+DEL button on the top right. Alternatively, you can also click [RESTART] to restart the server.

As soon as the boot process starts, press ESC to bring up the GRUB boot prompt. You may need to turn the system off from the control panel and then back on to reach 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 "linux /boot/") and add init="/bin/bash" at the end of the line (On CentOS 7, the line may start with linux16).

Press CTRL-X or F10 to boot.

System will boot and you will see the root prompt. Type "mount -rw -o remount /" and then "passwd" to change the root password and then reboot again. 6.1 For Ubuntu 17.04, the command may need to be mount -o remount,rw /.

Comments

Popular Posts

Install and configure rsyslog Centralized logging server in CentOS

How to fix postfix/smtp Network is unreachable error

Could not join realm: Necessary packages are not installed: sssd-tools sssd libnss-sss libpam-sss adcli