Can't connect to Ec2 instance

0

Trying to connect to ec2 using ssh, but it just won’t connect. What am I doing wrong?

  • Security rules are checked and they allow incoming ssh connection from my IP
  • Instance is running with 2 green status checks
  • Ping: 0 packets received
  • Ssh doesn’t work, after 2 minutes it says: “port 22: Operation timed out”
  • Licked my screen, didn't work, tasted funny (just kidding)
  • The server is still ‘serving’ the default Nginx page (I was setting things up for my website)

It happened right after I added a newly DNS record to the domain.com I want to use. I didn’t do anything else that might ‘break’ the connection or the server.

How should I deal with this?

Thanks for your response

  • Can you provide the error you're receiving from SSH? It would be helpful if you ran your ssh command in verbose logging mode (e.g. ssh -vvv)

asked 2 years ago460 views
3 Answers
0

You can try setting new SSH key pair once and try to login again. Please refer the below link for generating and setting up the new key pair for the instance: https://aws.amazon.com/premiumsupport/knowledge-center/user-data-replace-key-pair-ec2/

profile picture
answered 2 years ago
0

Hello,

One possible reason for this issue could be that the DNS record you added is somehow interfering with your SSH connection. To verify this, you can try connecting using the instance's IP address rather than the DNS record. Additionally, you can use the "dig" or "nslookup" commands to test if DNS resolution is functioning correctly.

For example:

  • dig domain.com
  • nslookup domain.com

If you are still unable to connect, I recommend that you check the network settings for your instance, specifically the Network Access Control Lists [2] and security groups [1] to verify if All ICMP protocol [3] is part of the rules with the correct source configured. Depending on the configurations these rules can block incoming/outgoing traffic and prevent successful communication between your instance and the internet. Also check that the instance has a public IP assigned. This should be the IP that DNS resolves to. And the route table has a default route 0.0.0.0/0 pointing to an IGW [6]. VPC flow logs can also be enabled to assist in troubleshooting the issue. With VPC flow logs enabled you can verify if traffic is reaching the EC2 instance and if there is any response traffic [5].

Additional: AWS provides detailed documentation on how to troubleshoot connectivity issues with EC2 instances, including step-by-step instructions for checking network configurations and resolving common issues [4].

References: [1] Security groups https://docs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html

[2] Network access control list (NACL) https://docs.aws.amazon.com/vpc/latest/userguide/vpc-network-acls.html

[3] Internet Control Message Protocol (ICMP) https://aws.amazon.com/what-is/icmp/

[4] Instance connectivity issues https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html

[5] Flow logs https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-cwl.html

[6] Internet gateway configurations (IGW) https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html

AWS
answered 2 years 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.

Guidelines for Answering Questions