Possible reasons for timeout when trying to access EC2 instance

后端 未结 24 1111
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 07:54

I cannot SSH into my instance - Operation timed out. What could be the reasons why, and what can I do to resolve it? Rebooting normally takes a long time to take effect, an

相关标签:
24条回答
  • 2020-12-04 08:44

    This answer is for the silly folks (like me). Your EC2's public DNS might (will) change when it's restarted. If you don't realize this and attempt to SSH into your old public DNS, the connection will stall and time out. This may lead you to assume something is wrong with your EC2 or security group or... Nope, just SSH into the new DNS. And update your ~/.ssh/config file if you have to!

    0 讨论(0)
  • 2020-12-04 08:44

    For me, it was that I had deleted everything from the boot volume. And couldn't connect to the instance anymore.

    0 讨论(0)
  • 2020-12-04 08:47

    I had the same problem, and the solution ended up being adding my local machine's IP to the list of inbound rules in the active security group. In the inbound dialog below, enter 22 in the port range, your local IP/32 in the source field, and leave 'custom tcp rule' in the dropdown.

    enter image description here

    0 讨论(0)
  • 2020-12-04 08:48

    Have you looked at the console output from the instance ? You can do this via the AWS console (Instances -> Right-click on the instance -> Get System Log). I've had occasions where the network services on an EC2 instance failed to start correctly, resulting in timed out SSH connections; restarting the instance usually fixed things.

    0 讨论(0)
  • 2020-12-04 08:48

    I had the same problem and I solved it by adding a rule to the security Groups

    Inbound SSH 0.0.0.0/0

    Or you can add your IP address only

    0 讨论(0)
  • 2020-12-04 08:50

    To connect use ssh like so:

    ssh -i keyname.pem username@xxx.xx.xxx.xx
    

    Where keyname.pem is the name of your private key, username is the correct username for your os distribution, and xxx.xx.xxx.xx is the public ip address.

    When it times out or fails, check the following:

    Security Group

    Make sure to have an inbound rule for tcp port 22 and either all ips or your ip. You can find the security group through the ec2 menu, in the instance options.

    Routing Table

    For a new subnet in a vpc, you need to change to a routing table that points 0.0.0.0/0 to internet gateway target. When you create the subnet in your vpc, by default it assigns the default routing table, which probably does not accept incoming traffic from the internet. You can edit the routing table options in the vpc menu and then subnets.

    Elastic IP

    For an instance in a vpc, you need to assign a public elastic ip address, and associate it with the instance. The private ip address can't be accessed from the outside. You can get an elastic ip in the ec2 menu (not instance menu).

    Username

    Make sure you're using the correct username. It should be one of ec2-user or root or ubuntu. Try them all if necessary.

    Private Key

    Make sure you're using the correct private key (the one you download or choose when launching the instance). Seems obvious, but copy paste got me twice.

    0 讨论(0)
提交回复
热议问题