Skip to content

Unable to SSH into AWS EC2 Instance – Connection Timed Out & Forgot Credentials

0

Hello,

I'm having trouble accessing my AWS EC2 instance via SSH. Here’s what’s happening:

When I try to SSH into my instance using the correct key file, I get the error: ssh: connect to host [EC2 Instance] port 22: Connection timed out I checked my security group rules, and I have port 22 open, but I may have misconfigured the source IP.

I also tried accessing the instance via EC2 Serial Console, but I forgot my Ubuntu user password.

What I’ve Tried So Far: Verified that my security group allows SSH (port 22). Changed the security group rule for SSH to "My IP" and 0.0.0.0/0 (temporarily). Restarted the EC2 instance. Questions: How can I regain SSH access to my instance? Since I forgot my Ubuntu user password, is there a way to reset it from AWS? Is there an alternative way to access my instance without SSH? Any help would be greatly appreciated. Thank you!

asked a year ago203 views
2 Answers
0

It sounds like you're facing a combination of connectivity and credential issues with your EC2 instance. Let's address these problems step by step:

  1. SSH Connection Timeout: The connection timeout suggests there might be network configuration issues beyond just the security group. While you've checked the security group rules, also ensure that:
  • Your VPC has an Internet Gateway attached
  • The subnet's route table has a route to the Internet Gateway (0.0.0.0/0 pointing to the IGW)
  • The Network ACLs are not blocking incoming SSH traffic
  • Your instance has a public IP address assigned
  1. Forgotten Ubuntu User Password: For the forgotten Ubuntu user password, you can reset it without needing to SSH into the instance. AWS provides a way to do this using the Systems Manager Automation feature:
  • Use the AWSSupport-ResetAccess runbook in AWS Systems Manager
  • This runbook can create a new SSH key for your current instance, allowing you to regain access
  • It works by creating a temporary VPC, launching a helper instance, attaching your original root volume, and using EC2Rescue to generate a new SSH key
  1. Alternative Access Methods: If SSH is not working, you have a few other options to access your instance:
  • EC2 Instance Connect: This feature allows you to connect to your instance directly from the AWS Management Console, bypassing potential local network issues
  • AWS Systems Manager Session Manager: If configured, this allows you to start a secure shell on your instance without needing SSH access
  1. Troubleshooting Steps:
  • Double-check all network configurations, including VPC settings, subnet configurations, and route tables
  • Use the VPC Reachability Analyzer to diagnose potential network configuration issues
  • Try connecting using the instance's public IP address instead of its public DNS name
  • Verify that there are no OS-level firewall rules (like iptables) blocking incoming connections
  1. Last Resort: If none of the above solutions work, you might want to consider:
  • Creating a new instance in a different subnet or region to isolate the issue
  • Contacting AWS Support for more in-depth assistance, especially if you suspect an issue with AWS infrastructure

Remember to make changes one at a time and test after each modification to identify which change resolves the issue. Also, once you regain access, it's crucial to review and tighten your security configurations to prevent future access issues while maintaining proper security practices.

Sources
Unable to ssh to an EC2 instance | AWS re:Post
Reset passwords and SSH keys on EC2 instances - AWS Systems Manager
Port 22: Connection Time Out Issue | AWS re:Post
Can't connect to Linux instance even after the health status checks pass | AWS re:Post

answered a year ago
EXPERT
reviewed a year ago
0

Hello.

If you are using Ubuntu, you may be able to use Systems Manager Session Manager.
Please follow the steps in the document below to set up an IAM role in EC2 and try connecting with Session Manager.
https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/connect-to-an-amazon-ec2-instance-by-using-session-manager.html

EXPERT
answered a year ago
EXPERT
reviewed a year ago

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.