Help Center> Elastic Cloud Server> Troubleshooting> Passwords and Key Pairs Issues> How Do I Reset the Password for User root in Single-User Mode on a Linux ECS?
Updated on 2023-04-03 GMT+08:00

How Do I Reset the Password for User root in Single-User Mode on a Linux ECS?

Scenarios

This section describes how to reset the password of user root in single-user mode on a Linux ECS.

This section applies to x86 ECSs.

Back up data before resetting the password of user root in single-user mode.

Select a method based on the OS of your ECS.

CentOS 8

  1. Remotely log in to the ECS

    Click Remote Login in the Operation column.

  2. Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
  3. When the interface for selecting a kernel appears, press the e key to go to the configuration interface for boot options.
    Figure 1 Entering the kernel editing mode
  4. Edit the boot options.

    Change ro to rw init=/sysroot/bin/bash.

    Figure 2 Before the change
    Figure 3 After the change
  5. Press Ctrl+X.
    Wait for the system to boot into the single-user mode.
    Figure 4 Single-user mode (emergency shell)
  6. Run the chroot /sysroot/ command to access the system.
  7. Run the following command to reset the password of user root:

    # passwd root

    Figure 5 Resetting the root password in single-user mode.
  8. (Optional) Run the following command to enable SELinux:

    # touch /.autorelabel

  9. Run the following command to exit the root directory:

    # exit

  10. Run the following command to restart the ECS:

    # reboot

CentOS 7 or EulerOS

  1. Remotely log in to the ECS using the VNC.

    Click Remote Login in the Operation column.

  2. Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
  3. When the interface for selecting a kernel appears, press the e key to go to the configuration interface for boot options.
    Figure 6 Entering the kernel editing mode

    For EulerOS, the GRUB file is encrypted by default. When you enter the kernel editing mode, you will be required to enter the username and password. Contact the customer service to obtain them.

  4. Locate the line containing linux16 and perform the following operations:
    1. Delete the parameters that do not need to be loaded (from ro to the end).

      Retain console=tty0 console=ttyS0 for BMS.

    2. Change ro to rw for remounting the root partition with read-write permissions.
    3. Add rd.break and press Ctrl+X.
      Figure 7 Before the change
      Figure 8 After the change
  5. Run the following command to go to the /sysroot directory:

    # chroot /sysroot

  6. Run the following command to reset the password of user root:

    # passwd root

  7. (Optional) Run the following command to enable SELinux:

    # touch /.autorelabel

  8. Run the following command to exit the root directory:

    # exit

  9. Run the following command to restart the ECS:

    # reboot

CentOS 6 or Red Hat 6

  1. Remotely log in to the ECS

    Click Remote Login in the Operation column.

  2. Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
  3. After the restart starts, press Esc repeatedly to prevent the system from starting and enter a grub menu.
    Figure 9 GRUB menu
  4. Use the arrow keys to select the first kernel and press e to edit the kernel.
    Figure 10 Entering the kernel editing mode
  5. Select the kernel line and press e again to edit this line.
    Figure 11 Selecting the kernel line
  6. Add 1 to the end of rd_NO_DM.
    Figure 12 Adding 1 to the end of the rd_NO_DM
  7. Delete console=ttyS0,115200n8 and press Enter.
    Figure 13 Deleting console=ttyS0,115200n8
  8. Press b to boot using the kernel and boot into runlevel 1 (single-user mode).
  9. When the prompt # is displayed, run the following command to reset the password:

    # passwd root

  10. Restart the ECS.

    # reboot

Debian or Ubuntu

  1. Remotely log in to the ECS

    Click Remote Login in the Operation column.

  2. Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
  3. After the restart starts, press Esc repeatedly to prevent the system from starting and enter a grub menu.
    Figure 14 GRUB menu
  4. Use the arrow keys to select a kernel and press e to enter the editing mode.
  5. Locate the line starting with linux, and replace the content from ro to the end of the line with rw init=/bin/bash (remount the root partition with read-write permissions).
    Figure 15 Editing boot options
  6. Press Ctrl+X to enter the single-user mode.
  7. Run the following command to reset the password of user root:

    # passwd root

  8. Run the following command to restart the ECS:

    # reboot

SUSE 11

  1. Remotely log in to the ECS

    Click Remote Login in the Operation column.

  2. Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
  3. Press the up or down arrow key to prevent automatic system startup, and enter the GRUB menu.
  4. Delete the content following Boot Options and add init=/bin/bash.
    Figure 16 Boot options
  5. Press Enter to enter the single-user mode.
  6. Run the following command to reset the password of user root:

    # passwd root

  7. Run the following command to restart the ECS:

    # reboot

SUSE 12

  1. Remotely log in to the ECS

    Click Remote Login in the Operation column.

  2. Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
  3. Press Esc to stop the countdown, and enter the GRUB menu.
    Figure 17 GRUB menu
  4. Use the arrow keys to select a kernel and press e to enter the editing mode.
  5. Locate the line starting with linux and add init=/bin/bash to the end of the line.
    Figure 18 Editing boot options
  6. Press Ctrl+X to enter the rescue mode.
  7. Run the following command to reset the password of user root:

    # passwd root

  8. Run the following command to restart the ECS:

    # reboot