Connection ec2 instance operation timeout error using ssh

8,489

Did you manage to resolve your ssh issue to your ec2 instance?

I also encountered ssh login issues while setting up my first ec2 instance.

Here was how I resolved my ssh login issue:

  • with your instance's security group, set your inbound SSH rule's Source IP to 0.0.0.0/0 first, and make sure you can get a working connection with this setting. Once you have your ssh connection working, you can then tighten access by changing Source IP to the IP range of the machine you are logging in from. Note that if this machine has a non-static public IP, then you will frequently have to change the Source IP setting for your SSH rule.

  • I have noticed from my own experience that if I try to ssh to my new instance without waiting for its status checks to complete, I would encounter a ssh timeout issue. This was especially true for a newly created instances. In your AWS console, there should be a 'State' and 'Status Checks' column for each of your instance. Make sure the 'State' entry for your instance shows 'running' (with a green circle next to it), and the 'Status Checks' entry shows '2/2 checks passed' (with a green circle and white tick). This could take awhile at times - so go get some snacks, then come back and try logging in again.

  • I have found enabling ssh verbosity when helpful for debugging ssh issues too. Try this command to enable verbosity:

    ssh -vvv -i private_key.pem root@my_instance_public_domain

  • pinging your instance's public FQDN may also help, but make sure your instance's Security Group rules are set to allow ICMP traffic.

  • trying to telnet to port 22 of your instance's public FQDN may also help with troubleshooting. e.g.

    telnet my_instance_public_domain 22

Share:
8,489

Related videos on Youtube

arnold
Author by

arnold

Updated on September 18, 2022

Comments

  • arnold
    arnold over 1 year

    After creating a new instance, I am trying to access my instance like below:

    ssh -i private_key.pem root@my_instance_public_domain
    

    but the operation is timing out. I have updated the private key file permission using

    chmod 400
    

    and also edited default security group by adding a new in bound rule, selecting SSH and source Ip as 1.12.34.0/32

    but getting port 22: Operation timed out.

    What I am missing.

    • sunnysideup
      sunnysideup almost 12 years
      Is the ip you are connecting from 1.23.34.0/32? If not you have to modify the security group. You must also ensure that the instance is part of your security group
    • arnold
      arnold almost 12 years
      my ip is 1.23.34.0.what doest it mean "You must also ensure that the instance is part of your security group "?
    • sunnysideup
      sunnysideup almost 12 years
      this just means you have to make sure that the instance must be assigned to your security group. Just to be sure 1.23.34.0 must be your external ip address. Another problem (but unlikely problem if you use a provided AMI) may be that your instace has no ssh server running / has customized firewall rules.
    • arnold
      arnold almost 12 years
      I have already added the instance under the security group it is default and in that security group I have set ssh using my ip
  • frzsombor
    frzsombor over 2 years
    Dear Downvoter: consider adding a comment if you think this answer can be improved?
  • AdminBee
    AdminBee over 2 years
    Welcome to the site, and thank you for your contribution. Although I'm not the downvoter, please keep in mind that your answer relies heavily on externally linked content. Link-only-answers are discouraged however as links may become defunct or the linked content change. Please consider summarizing the necessary steps for setting up the route in your post.