Help Center> Huawei Cloud Flexus> FAQs> Password Management> Resetting the Password for Logging In to a Linux HECS Without Password Reset Plug-ins Installed

Resetting the Password for Logging In to a Linux HECS Without Password Reset Plug-ins Installed

Scenarios

If your Linux HECS has not had password reset plug-ins installed, follow the instructions provided in this section to reset the password.

This section describes how to reset the password of user root. After resetting the password, you can log in to the HECS, and change the private key or reset the password of a non-root user.

For details about the operations performed on Windows HECSs, see Resetting the Password for Logging In to a Windows HECS Without Password Reset Plug-ins Installed.

HECSs created using a public image have one-click password reset plug-ins installed by default. To reset the password, see Resetting an HECS Password on the Management Console.

Prerequisites

  • A temporary Linux HECS which locates in the same AZ as the target HECS is available.
  • The temporary HECS has an EIP bound.

Procedure

  1. Download the script for resetting the password and upload the script to the temporary HECS.

    Download the password reset script. Use a connection tool, such as WinSCP, to upload the obtained changepasswd.sh script to the temporary HECS.

    To download WinSCP, log in at https://winscp.net/.

  2. Stop the original HECS, detach the system disk from it, and attach the system disk to the temporary HECS.
    1. Stop the original Linux HECS, switch to the page providing details about the HECS, and click the Disks tab.

      Do not forcibly stop the original HECS. Otherwise, password reset may fail.

    2. Locate the row containing the system disk to be detached and click Detach to detach the system disk from the HECS.
    3. On the page providing details about the temporary HECS, click the Disks tab.
    4. Click Attach Disk. In the displayed dialog box, select the system disk detached in step 2.b and attach it to the temporary HECS.
  3. Log in to the temporary HECS remotely and reset the password.
    1. Locate the row containing the temporary HECS and click Remote Login in the Operation column.
    2. Run the following command to view the directory of the system disk detached from the original Linux HECS and now attached to the temporary HECS:

      fdisk -l

    3. Run the following commands in the directory where the script is stored to run the script for resetting the password:

      chmod +x changepasswd.sh

      ./changepasswd.sh

      When you run the password reset script, if the system displays a message indicating that there is no command related to logical volume manager (LVM), such as the message "no lvs command", install an LVM tool on the temporary HECS. The LVM2 tool is recommended, which can be installed by running the yum install lvm2 command.

      If the original HECS and the temporary HECS both run CentOS 7, a mount failure may occur during script execution. To resolve this issue, replace mount $dev $mountPath with mount -o nouuid $dev $mountPath in the script.

    4. Enter the new password and the directory obtained in step 3.b as prompted.
      If the following information is displayed, the password has been changed:
      set password success.
  4. For a non-root user, perform the following operations to enable the login permission of user root:

    vi /etc/ssh/sshd_config

    Modify the following parameters:

    • Change PasswordAuthentication no to PasswordAuthentication yes.

      Alternatively, delete the comment tag (#) before PasswordAuthentication yes.

    • Change PermitRootLogin no to PermitRootLogin yes.

      Alternatively, delete the comment tag (#) before PermitRootLogin yes.

    • Change the AllowUsers value to AllowUsers root.

      Search for AllowUsers in the file. If AllowUsers is unavailable, add it at the end of the file.

  5. Stop the temporary HECS, detach the system disk from it, attach the system disk to the original HECS, and restart the original HECS.
    1. Stop the temporary HECS, switch to the page providing details about the HECS, and click the Disks tab.
    2. Click Detach to detach the data disk attached in step 2.
    3. On the page providing details about the original Linux HECS, click the Disks tab.
    4. Click Attach Disk. In the displayed dialog box, select the data disk detached in step 5.b and device name /dev/sda.
    5. Restart the original Linux HECS.