- Newest
- Most votes
- Most comments
Steps to Reset the EC2 User Password
Stop the EC2 Instance:
Go to the AWS Management Console.
Navigate to the EC2 Dashboard.
Select the instance you need to reset the password for.
Click on the Instance State drop-down and select Stop.
Detach the Root Volume:
Once the instance is stopped, select the instance.
In the Description tab, note the Root device value (e.g., /dev/sda1).
Go to the Elastic Block Store > Volumes.
Find the root volume attached to your instance (using the Root device value noted).
Select the volume and click Actions > Detach Volume.
Attach the Root Volume to a Temporary Instance:
Launch a temporary EC2 instance in the same availability zone.
Once the instance is running, go back to the Volumes section.
Select the detached root volume and click Actions > Attach Volume.
Attach the volume to the temporary instance, use a different device name (e.g., /dev/sdf).
Modify the Password on the Temporary Instance:
Connect to the temporary instance via SSH using your key pair.
Mount the attached volume:
sudo mkdir /mnt/tempvol
sudo mount /dev/xvdf1 /mnt/tempvol
Change the root to the mounted volume
sudo chroot /mnt/tempvol
Reset the password for the desired user
passwd username
Unmount the Volume and Reattach It:
exit
Unmount the volume
sudo umount /mnt/tempvol
Go back to the AWS Management Console.
Detach the volume from the temporary instance.
Reattach the volume to the original instance as the root volume (/dev/sda1).
Restart the Original Instance:
Go back to the EC2 Dashboard.
Select your original instance.
Click on Instance State and select Start.
Connect to the Original Instance:
Once the instance is running, connect via SSH using your key pair.
Verify that you can log in with the new password.
Connect to Your EC2 Instance via SSH:
Use SSH to connect to your EC2 instance using the SSH key pair you have associated with the instance:
ssh -i /path/to/your/key.pem ec2-user@your-instance-public-dns
Reset the Password:
sudo passwd username
Follow the Prompts:
You will be prompted to enter a new password. Type and confirm the new password as instructed. No need to enter the current password since you are using sudo. Verify the New Password:
Once the password is successfully changed, you can test it by disconnecting from the instance (exit command) and then reconnecting with the new password to ensure it works. Optional: Disable Password Authentication (Recommended for Security):
For improved security, after resetting the password, consider disabling password authentication and using SSH key pairs exclusively for authentication. To do this, edit the SSH daemon configuration file (/etc/ssh/sshd_config) and set PasswordAuthentication no. Then, restart the SSH service (sudo systemctl restart sshd).
The "sudo passwd username" method requires me to enter the current user password
Steps to Reset the EC2 User Password Stop the EC2 Instance:
Go to the AWS Management Console. Navigate to the EC2 Dashboard. Select the instance you need to reset the password for. Click on the Instance State drop-down and select Stop. Detach the Root Volume:
Once the instance is stopped, select the instance. In the Description tab, note the Root device value (e.g., /dev/sda1). Go to the Elastic Block Store > Volumes. Find the root volume attached to your instance (using the Root device value noted). Select the volume and click Actions > Detach Volume. Attach the Root Volume to a Temporary Instance:
Launch a temporary EC2 instance in the same availability zone. Once the instance is running, go back to the Volumes section. Select the detached root volume and click Actions > Attach Volume. Attach the volume to the temporary instance, use a different device name (e.g., /dev/sdf). Modify the Password on the Temporary Instance:
Connect to the temporary instance via SSH using your key pair. Mount the attached volume sudo mkdir /mnt/tempvol sudo mount /dev/xvdf1 /mnt/tempvol
Change the root to the mounted volume
sudo chroot /mnt/tempvol
Reset the password for the desired user passwd username
Unmount the Volume and Reattach It: exit Unmount the volume sudo umount /mnt/tempvol
Go back to the AWS Management Console. Detach the volume from the temporary instance. Reattach the volume to the original instance as the root volume (/dev/sda1). Restart the Original Instance:
Hi
Reset Password using AWS Management Console (if applicable):
This method only works if:
- You have access to the AWS Management Console with IAM user credentials that have administrator access to the EC2 instance.
- You haven't disabled password login for the user (usually ec2-user for Amazon Linux or Ubuntu AMIs).
Here's how to proceed:
- Login to the AWS Management Console.
- Navigate to the EC2 service.
- Select the instance you want to access.
- Click on "Actions" and then select "Instance Settings" -> "Get System Log".
- Look for logs related to password resets. These might contain a temporary password for the user.
- Once you have the temporary password, connect to the EC2 instance using SSH and the temporary password.
- After gaining access, use the passwd command to set a new, strong password for the user.
For More Reset Passwords please follow the link:
https://docs.aws.amazon.com/systems-manager/latest/userguide/managed-instances-password-reset.html
Relevant content
- asked 2 years ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 months ago

I stopped the server and changed the password by modifying the user metadata: echo "ec2 user: new_password" | chpasswd. The Amazon console prompted that the change was successful, but the password was still incorrect after starting the instance