The root is the username or account that, by default, has access to all commands and files on a Linux or other Unix-like operating system. It is also referred to as the root account, root user, and the superuser.
In case if you are using ISO for installing Linux operation system, then you have to use Single User Mode to reset the root password.
This guide outlines the steps to reset root password in various Linux distributions such as CentOS, Ubuntu and Debian.
CentOS 8
Log in to server via Console
option from LayerPanel v2.0 and click Send CtrlAltDel
button to reboot the server and access the boot menu.
Once the GRUB boot prompt
shows up telling to press any key
, perform this action to enter the GRUB prompt. (There will only be a few seconds to press a key to stop the automated booting process, if this is not done on time, the server would need to be restarted again)
From the GRUB boot prompt, press the E
button to edit the first boot option.
Find the kernel line starting with linux
and change ro
to rw init=/sysroot/bin/sh
.
# rw init=/sysroot/bin/sh
Press CTRL+X
or F10
to save the changes and boot the server into single user mode.
Access the system with the below command.
# chroot /sysroot
Type in the command passwd
to set the new password. The password would need to be entered twice.
# passwd
Run the below command to force file-system relabeling.
# touch /.autorelabel
Reboot the system: reboot -f.
# reboot -f
Wait for some time, as the relabeling will take few minutes to get completed. Once this is completed, the server will be restarted once again automatically.
Test the newly reset password once the login screen shows up.
CentOS 7
Log in to server via Console
option from LayerPanel v2.0 and click Send CtrlAltDel
button to reboot the server and access the boot menu.
Once the GRUB boot prompt
shows up telling to press any key
, perform this action to enter the GRUB prompt. (There will only be a few seconds to press a key to stop the automated booting process, if this is not done on time, the server would need to be restarted again)
From the GRUB boot prompt, press the E
button to edit the first boot option.
Find the kernel line starting with linux16
and change ro
to rw init=/sysroot/bin/sh
.
# rw init=/sysroot/bin/sh
Press CTRL+X
or F10
to save the changes and boot the server into single user mode.
Access the system with the command: chroot /sysroot
and press ENTER
.
# chroot /sysroot
Type in the command passwd
to set the new password. The password would need to be entered twice.
# passwd
Reboot the system: reboot -f.
# reboot -f
Test the newly reset password once the login screen shows up.
Alternative Method for CentOS 8 & 7
Log in to server via Console
option from LayerPanel v2.0 and click Send CtrlAltDel
button to reboot the server and access the boot menu.
Once the GRUB boot prompt
shows up telling to press any key
, perform this action to enter the GRUB prompt. (There will only be a few seconds to press a key to stop the automated booting process, if this is not done on time, the server would need to be restarted again)
From the GRUB boot prompt, press the E
button to edit the first boot option.
At the GRUB menu, select the kernel line starting with linux16
and press END key
. This will take you to the end of the line. Here type in rd.break console=tty1
.
# rd.break console=tty1
Press CTRL+X
or F10
to save the changes and boot the server into single user mode.
The server will be booted into the switch-root prompt.
When using rd.break
, the system will be directly mounted on /sysroot
in read-only mode and it needs to be remounted in read/write mode. The below command helps in this.
# mount -o remount,rw /sysroot
Switch into a chroot jail using the below command, where /sysroot
is treated as the root of the filesystem tree.
# chroot /sysroot
Type in the command passwd
to set the new password. The password would need to be entered twice.
# passwd
Reboot the system: reboot -f.
# reboot -f
Test the newly reset password once the login screen shows up.
CentOS 6
Log in to server via Console
option from LayerPanel v2.0 and click Send CtrlAltDel
button to reboot the server and access the boot menu.
Once the GRUB boot prompt
shows up telling to press any key
, perform this action to enter the GRUB prompt. (There will only be a few seconds to press a key to stop the automated booting process, if this is not done on time, the server would need to be restarted again)
From the GRUB boot prompt, press the E
button to edit the first boot option.
At the GRUB menu, select the line that starts with kernel
and then press the E
button to edit the kernel.
Add the text single to the end of this line and press ENTER
to save the changes.
Press the B
button to boot the server to these temporary options to reset the root password.
The server will boot up to the root shell. Type in the command passwd
to set the new password. The password would need to be entered twice.
# passwd
Once this has been complete, reboot the server and verify access to the server using the new password.
# reboot
Test the newly reset password once the login screen shows up.
Debian & Ubuntu
Log in to server via Console
option from LayerPanel v2.0 and click Send CtrlAltDel
button to reboot the server and access the boot menu.
Once the GRUB boot prompt
shows up telling to press any key
, perform this action to enter the GRUB prompt. (There will only be a few seconds to press a key to stop the automated booting process, if this is not done on time, the server would need to be restarted again)
From the GRUB boot prompt, press the E
button to edit the first boot option.
In the GRUB menu, find the kernel line starting with linux /boot/
and add init=/bin/bash
at the end of the line.
# init=/bin/bash
Press CTRL+X
or F10
to save the changes and boot the server into single user mode. Once booted the server will boot into root prompt.
Type in the command mount -o remount,rw /
# mount -o remount,rw /
Type in the command passwd
to set the new password. The password would need to be entered twice.
# passwd
Reboot the system: reboot -f.
# reboot -f
Test the newly reset password once the login screen shows up.
Fedora
Log in to server via Console
option from LayerPanel v2.0 and click Send CtrlAltDel
button to reboot the server and access the boot menu.
Once the GRUB boot prompt
shows up telling to press any key
, perform this action to enter the GRUB prompt. (There will only be a few seconds to press a key to stop the automated booting process, if this is not done on time, the server would need to be restarted again)
From the GRUB boot prompt, press the E
button to edit the first boot option.
Find the kernel line starting with linux
, linux16
or linuxefi
, change ro
to rw init=/sysroot/bin/sh
.
# rw init=/sysroot/bin/sh
Press CTRL+X
or F10
to save the changes and boot the server into single user mode.
Remount the hard drive with read-write permission.
# mount –o remount,rw /sysroot
Access the system with the command: chroot /sysroot
and press ENTER
.
# chroot /sysroot
Type in the command passwd
to set the new password. The password would need to be entered twice.
# passwd
Reboot the system: /sbin/reboot -f.
# /sbin/reboot -f
Test the newly reset password once the login screen shows up.