Reset EC2 SSM Password: Step-by-Step Guide
In this article
To reset the password for an EC2 instance managed by AWS Systems Manager (SSM), you use the SSM Run Command feature to execute a script on the instance that sets a new password for the local administrator or user account. This works without needing to SSH or RDP into the instance, as long as the SSM Agent is installed and the instance has an IAM role with the necessary permissions. You'll need the instance ID, the new password, and access to the AWS Management Console or AWS CLI.
What You'll Need
- An EC2 instance with the SSM Agent installed and running (most recent Amazon Linux, Ubuntu, and Windows AMIs include it).
- An IAM role attached to the instance that grants SSM permissions (e.g.,
AmazonSSMManagedInstanceCorepolicy). - The instance must be registered as a managed instance in Systems Manager (check the Fleet Manager console).
- Access to the AWS Management Console or AWS CLI with permissions to run SSM commands.
- The exact username for which you want to reset the password (e.g.,
Administratoron Windows,ec2-useron Amazon Linux,ubuntuon Ubuntu).
Step-by-Step
- Open the Systems Manager console – Sign in to the AWS Management Console, navigate to AWS Systems Manager, and select Run Command from the left menu. (Note: menu labels may vary slightly by AWS region or console version.)
- Choose the command document – Click Run command. In the Command document search box, type
AWS-RunShellScriptfor Linux instances orAWS-RunPowerShellScriptfor Windows instances. Select the appropriate document. - Set the command parameters – In the Command parameters section, you will provide a script that resets the password. For Linux, use a shell script like:
echo 'ec2-user:NewPassword123!' | chpasswd
Replaceec2-userwith the actual username andNewPassword123!with your chosen strong password. For Windows, use a PowerShell script like:
net user Administrator 'NewPassword123!'
(Adjust the username if needed.) - Select the target instances – In the Targets section, choose Choose instances manually and select the EC2 instance from the list. Ensure the instance is in the Online state (green dot).
- Configure execution options (optional) – Set Rate control to a reasonable value (e.g., 1 instance at a time) and leave other options as defaults. You can also set a timeout (e.g., 60 seconds).
- Run the command – Click Run. The command will execute on the instance. You can watch the status in the Run Command history.
- Verify the result – Once the status shows Success, test the new password by attempting to log in via RDP (Windows) or SSH (Linux). If the login fails, check the command output for errors.
Common Mistakes
- Wrong username – Using a username that doesn't exist on the instance (e.g.,
rooton Ubuntu where root login is disabled). Check the AMI documentation for the default user. - Password not meeting complexity requirements – Windows requires a password with at least 8 characters, including uppercase, lowercase, and numbers/symbols. If the password is too weak, the command may fail.
- SSM Agent not running – If the instance is not online in Fleet Manager, the command won't execute. Ensure the SSM Agent is installed and the instance has outbound internet access to the SSM endpoints.
- Missing IAM permissions – The instance's IAM role must include the
AmazonSSMManagedInstanceCorepolicy. Without it, the instance won't appear as a managed instance. - Using the wrong command document – Running a PowerShell script on a Linux instance or vice versa will fail. Select the correct document for your OS.
Tips
- Use a temporary password – After resetting, log in and immediately change the password again to something you won't forget, or use a password manager.
- Enable SSM Session Manager – Instead of resetting passwords, consider using SSM Session Manager to access the instance without any password. This is more secure and avoids password management altogether.
- Test the script locally – If you're unsure about the script syntax, test it on a test instance first to avoid locking yourself out.
- Use AWS CLI for automation – If you need to reset passwords frequently, use the
aws ssm send-commandCLI command with the same parameters. This can be scripted.
Troubleshooting
If the command fails with an error like "Instance is not in a valid state" – Check that the instance is running and the SSM Agent is online. Restart the SSM Agent on the instance (via the console or by rebooting the instance) and try again.
If the command succeeds but the password doesn't work – Verify the username is correct. For Linux, check if the user is locked (e.g., passwd -S username). For Windows, ensure the account is not disabled. Also, confirm the password meets the OS policy (e.g., Windows may require a password change at next logon).
If the instance doesn't appear in the target list – Make sure the instance is in the same AWS region as your SSM console. Also, check that the IAM role is correctly attached and the SSM Agent is installed. You may need to manually install the agent if the AMI doesn't include it.
If the command times out – Increase the timeout in the Run Command settings. Also, check the instance's network connectivity – it must be able to reach the SSM endpoints (usually via VPC endpoints or internet).
Frequently Asked Questions
Can I reset the password for an EC2 instance without the SSM Agent?
No, the SSM Agent must be installed and running. If it's not, you'll need to use the EC2 Instance Connect (for Linux) or the AWS Management Console's RDP password retrieval (for Windows, if you have the key pair).
What if I don't know the username?
For Amazon Linux, the default is ec2-user; for Ubuntu, it's ubuntu; for Windows, it's Administrator. You can also check the AMI documentation or use SSM to run a command to list users (e.g., cat /etc/passwd).
Will this work on instances in a private subnet?
Yes, as long as the instance can reach the SSM endpoint (via a VPC endpoint or NAT gateway). The command is sent over the SSM channel, not over the internet directly.
Can I reset the password for a non-default user?
Yes, just replace the username in the script with the correct one. Ensure the user exists and has the right permissions.
Is there a way to reset the password without using a script?
For Windows, you could use the EC2 console's "Get Windows Password" if you have the key pair, but that only works for the initial password. For Linux, you'd need to use SSH with a key pair. SSM Run Command is the most flexible method.
What if I get a "Permission denied" error when running the command?
Check that the IAM role attached to the instance has the AmazonSSMManagedInstanceCore policy. Also, ensure the user running the command in the console has permissions to invoke SSM (e.g., AmazonSSMFullAccess).