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
asked 4 months ago534 views
3 Answers
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

answered 4 months ago
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
EXPERT
shibata
answered 4 months ago
-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
answered 4 months ago
profile pictureAWS
EXPERT
reviewed 4 months ago
  • Thanks for the suggestion, however, there are no such entries in the system log.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions