Resetting root password by booting into Single User Mode from Linux GRUB

2019-12-05 By Aaron 1384 Views linux single user mode root password
1 reviews

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


  1. 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.

  2. 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)

  3. From the GRUB boot prompt, press the E button to edit the first boot option.

  4. Find the kernel line starting with linux and change ro to rw init=/sysroot/bin/sh.

    # rw init=/sysroot/bin/sh
    

    centos8pw1

    centos8pw2

  5. Press CTRL+X or F10 to save the changes and boot the server into single user mode.

  6. Access the system with the below command.

    # chroot /sysroot
    

    centos8pw3

  7. Type in the command passwd to set the new password. The password would need to be entered twice.

    # passwd
    

    centos8pw4

  8. Run the below command to force file-system relabeling.

    # touch /.autorelabel
    
  9. 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.

  10. Test the newly reset password once the login screen shows up.


CentOS 7


  1. 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.

  2. 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)

  3. From the GRUB boot prompt, press the E button to edit the first boot option.

  4. Find the kernel line starting with linux16 and change ro to rw init=/sysroot/bin/sh.

    # rw init=/sysroot/bin/sh
    

    centos7pw1

    centos7pw2

  5. Press CTRL+X or F10 to save the changes and boot the server into single user mode.

  6. Access the system with the command: chroot /sysroot and press ENTER.

    # chroot /sysroot
    

    centos7pw3

  7. Type in the command passwd to set the new password. The password would need to be entered twice.

    # passwd
    

    centos7pw4

  8. Reboot the system: reboot -f.

    # reboot -f
    
  9. Test the newly reset password once the login screen shows up.


Alternative Method for CentOS 8 & 7


  1. 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.

  2. 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)

  3. From the GRUB boot prompt, press the E button to edit the first boot option.

  4. 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
    

    centos87pw1

  5. Press CTRL+X or F10 to save the changes and boot the server into single user mode.

  6. The server will be booted into the switch-root prompt.

  7. 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
    

    centos87pw2

  8. Switch into a chroot jail using the below command, where /sysroot is treated as the root of the filesystem tree.

    # chroot /sysroot
    

    centos87pw3

  9. Type in the command passwd to set the new password. The password would need to be entered twice.

    # passwd
    

    centos87pw4

  10. Reboot the system: reboot -f.

    # reboot -f
    
  11. Test the newly reset password once the login screen shows up.


CentOS 6


  1. 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.

  2. 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)

  3. From the GRUB boot prompt, press the E button to edit the first boot option.

  4. At the GRUB menu, select the line that starts with kernel and then press the E button to edit the kernel.

  5. Add the text single to the end of this line and press ENTER to save the changes.

    centos6pw1

  6. Press the B button to boot the server to these temporary options to reset the root password.

  7. 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
    

    centos6pw2

  8. Once this has been complete, reboot the server and verify access to the server using the new password.

    # reboot 
    
  9. Test the newly reset password once the login screen shows up.


Debian & Ubuntu


  1. 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.

  2. 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)

  3. From the GRUB boot prompt, press the E button to edit the first boot option.

  4. 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
    

    debianubuntupw1

  5. 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.

  6. Type in the command mount -o remount,rw /

    # mount -o remount,rw /
    

    debianubuntupw2

  7. Type in the command passwd to set the new password. The password would need to be entered twice.

    # passwd
    

    debianubuntupw3

  8. Reboot the system: reboot -f.

    # reboot -f
    
  9. Test the newly reset password once the login screen shows up.


Fedora


  1. 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.

  2. 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)

  3. From the GRUB boot prompt, press the E button to edit the first boot option.

  4. Find the kernel line starting with linux, linux16 or linuxefi, change ro to rw init=/sysroot/bin/sh.

    # rw init=/sysroot/bin/sh
    

    fedorapw2

    fedorapw3

  5. Press CTRL+X or F10 to save the changes and boot the server into single user mode.

  6. Remount the hard drive with read-write permission.

    # mount –o remount,rw /sysroot
    
  7. Access the system with the command: chroot /sysroot and press ENTER.

    # chroot /sysroot
    

    fedorapw4

  8. Type in the command passwd to set the new password. The password would need to be entered twice.

    # passwd
    

    fedorapw5

  9. Reboot the system: /sbin/reboot -f.

    # /sbin/reboot -f
    
  10. Test the newly reset password once the login screen shows up.


Related Tutorials

What do you think about this article?

Rate this article