Reset EC2 user password

-1

A while back, someone handed over the admin of an EC2 instance to me. They created an account for me and added my SSH key into the authorized_keys file. I can SSH into the instance, however, I do not have the password for sudo. I also have access to the AWS console (incl. the root credentials). What is the easiest way to update my EC2 user account password?

  • Depending on the OS configuration, you may be able to switch to root with su - without a password, if your user is a member of a suitable group (e.g. wheel)

  • Thanks, @James_S - unfortunately, it prompts me for the password

pemm87
已提問 2 個月前檢視次數 339 次
3 個答案
0

In this case there are few ways to set ways to recover password:

  1. If you SSM agent is installed then you can login to the server using Systems Manager and you can give sudo access for that user from there.

There is another way but downtime will be needed.

  1. In other way you can use helper instance in same AZ. You need to stop the problematic server then detach the root volume and attach it to helper instance.

  2. Then mount it.

  3. Then make entry for that user in sudoers file to allow him sudo access.

    For mounting reference:- https://repost.aws/knowledge-center/ec2-linux-emergency-mode

已回答 2 個月前
0

It is not even possible to connect with SSM. If that is the case, the second method of Jahangeer Alam is good.

Another way is to get an AMI and set up a new instance. This also has the disadvantages of slight downtime and changing the public IP address, but you can set your private key to ec2-user when you create the instance.

The ec2-user is generally allowed to sudo without a password.

profile picture
專家
shibata
已回答 2 個月前
-1

If you have access to the AWS console with root credentials, the easiest way to update your EC2 user account password is by following these steps:

  1. Log in to the AWS Management Console.

  2. Navigate to the EC2 dashboard.

  3. Select the EC2 instance for which you want to update the password.

  4. Click on "Actions" and then select "Instance Settings" > "Get System Log".

  5. Look for the log entry that includes "Resetting password for user <your_username>". This entry contains the temporary password generated for your user.

  6. Copy the temporary password.

  7. SSH into the EC2 instance using your SSH key.

  8. Once logged in, use the temporary password to set a new password for your user account using the command:

    sudo passwd <your_username>

  9. Follow the prompts to set a new password.

After setting the new password, you should be able to use sudo with your updated credentials.

zouz
已回答 2 個月前
profile pictureAWS
專家
已審閱 2 個月前
  • Thanks for the suggestion, however, there are no such entries in the system log.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南