How To Reset Root Password On CentOS 6, 7, 8, 9 —
Resetting/Recovering Forgotten Root User Account Password in RHEL/CentOS 7
What if you forget your root password? You cannot reset root account password using user account. Since user account is not permitted to perform such task in general.
Here in this article we will be taking you to the journey of resetting your RHEL 7 and CentOS 7 root password.
Please note that CentOS 7 and RHEL 7 comes with GRUB version 2. It is not possible to reset root password in a single-user mode which was supported in RHEL 6.x and CentOS 6.x. The root password now operates in Single-User Mode and in emergency Mode.
1 – In the Boot Grub Menu Select Option to Edit
2 – Select Option to edit (e)
3 – Go to the line of Linux 16 and change ro with “rw init=/sysroot/bin/sh”
4 – Now press “Control+x” to start on single user mode
5 – Now access the system with this command
chroot /sysroot
6 – Reset the password
passwd root
7 – Update selinux information
touch /.autorelabel
8 – Exit Chroot
exit
9 – Reboot your system
reboot
That’s all for now. I’ll be here again with another interesting article soon. Till then stay tuned and connected to LIVEMNC. Don’t forget to provide us with your valuable feedback in the comments below.
Also You’ll find instructions below for CentOS 6, 7, 8, 8 Stream, and 9 Stream.
CentOS 6
-
-
-
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.
-
At the GRUB prompt, type A to append to the boot command.
-
Add a space and the text
single
to the end of the line. -
Press ENTER.
-
The system will boot, and you will see the root prompt.
-
Type
passwd
and follow the prompts to change the root password. -
Run
reboot
to reboot the server.
-
-
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
torw 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. 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. -
Run
exit
. -
Run
reboot -f
to reboot the server.
-
-
CentOS 8 & CentOS 8 Stream
-
-
-
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
torw 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. 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. -
Run
exit
. -
Run
logout
. -
Run
reboot
to reboot the server.
-
-
CentOS 9 Stream
-
-
-
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, use the arrow keys to highlight one of the rescue kernels and press E to edit the boot options.
-
Find the kernel line starting with linux.
-
Change
ro
torw init=/sysroot/bin/sh
. -
Press CTRL+X or F10 to boot into single user mode.
-
Press ENTER to enter maintenance 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. 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. -
Run
exit
. -
Run
reboot
to reboot the server.
-
-
Leave A Comment