Help Center/ Elastic Cloud Server/ Troubleshooting/ Passwords and Key Pairs Issues/ How Do I Reset the Password for Logging In to a Linux ECS?
Updated on 2023-04-03 GMT+08:00

How Do I Reset the Password for Logging In to a Linux ECS?

Scenarios

This section describes how to reset the password of a Linux ECS by reattaching the system disk.

The method in this section only applies to x86 ECSs running CentOS 7, Ubuntu, or EulerOS.

Detaching the system disk from the ECS is involved. To prevent data loss, back up data in advance.

Prerequisites

  • A temporary Linux ECS which locates in the same AZ as the target ECS is available.
  • An EIP has been bound to the temporary ECS.

Procedure

  1. Stop the ECS, detach the system disk, and attach the system disk to the temporary ECS.
    1. Stop the ECS, go to its details page, and click the Disks tab.

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

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

      fdisk -l

      Figure 1 Viewing the directory of the system disk
    3. Create a temporary directory and mount the system disk to it.

      mkdir /aaz

      mount /dev/vdb1 /aaz

    4. Switch to the directory where the system disk is mounted.

      chroot /aaz

      Figure 2 Switching to the mount directory
    5. Run the following command and enter a new password as prompted:
      passwd
      Figure 3 Setting a new password
      If the following information is displayed, the password has been reset:
      all authentication tokens updated successfully.
  3. Stop the temporary ECS, detach the system disk, attach the system disk back to the ECS, and restart the ECS.
    1. Stop the temporary ECS, switch to its details page, and click the Disks tab.
    2. Click Detach to detach the disk that is attached in step 1.
    3. On the details page of the ECS, click the Disks tab.
    4. Click Attach Disk. In the displayed dialog box, select the disk detached in step 3.b and device name /dev/sda.
    5. Restart the ECS.