5

I am having a problem connecting with my Ubuntu 16.04 ec2 instance on aws. I have added my public key to authorized keys file and also added my ip for ssh access on port 22 using Myip.

I am trying to connect using normal way:

ssh [email protected] 

I have even rebooted my ec2 instance.

What else do I need to do to get access?

Thanks

1
  • That command line doesn't appear to use your private key, unless you've done that some other way. However timed out usually means a firewall type issue, security group, network ACL, or a local issue. Perhaps try ssh'ing from an AWS spot instance. Commented Mar 14, 2018 at 19:25

7 Answers 7

8

Normally, to solve ssh connection issues in aws you can check the following things:

Check if your instance is up.

Allow 22 port in security group: check if the security group you have edited is assigned to instance. Also, only for test allow 0.0.0.0/0 (all ips) to 22 port.

Check if your AMI has ubuntu user, you can try with user admin too.

Check if the ip of the instance is public.

If all of this is correct, the problem probabilly will be in the pair public-private key. Look up with pair you use when you launch the instance and your default key is the rigth key.

5
  • I think it is because of ssh key generated by my highsierra OSx....as I cant even connect to my Linode instance, basically ssh is not connecting to anything at all. Commented Mar 14, 2018 at 13:37
  • Can be related with this? discussions.apple.com/thread/7685687 Commented Mar 14, 2018 at 15:22
  • No it is not related with the problem mentioned in the link. Commented Mar 14, 2018 at 18:56
  • 1
    Also check Network ACLs, though it's usually not that. Commented Mar 14, 2018 at 19:24
  • "Check if your instance is up". This also means that if everything else looks fine, try rebooting your instance. Commented Oct 9, 2023 at 20:07
1

I almost always find it due to either incorrect security configurations (whether that be with the security group on AWS or the security configurations on the instance itself like Nginx) or too much storage used. Once you go past around 80% storage on the instance it tends to behave erratically, most likely due to internal fragmentation. In the latter case I would recommend looking under the heading "Specify instance user data at launch" of the following link:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

Essentially, you will need to stop your instance, click the instance ID, actions -> instance settings -> Edit User Data. Here you will be able to add code onto the instance that could delete files, which would allow you to log on. Or, if you have security configurations with Nginx, you can delete them.

0

This could be a DNS issue. Try to put the IP address of your EC2 instance instead:

ssh -i <your_pem_key> <username>@<ip-address> 
0

option 3 if you are on a VPN and the ip is private, use an elastic ip address to make it public by associating it with the running instance

1
  • via aws elastic IP address Commented Jan 23, 2020 at 20:19
0

i was using amazon EC2 many months without issues but recently i am getting this too. i am using Google public DNS as my DNS, not sure if it is related. i am also not sure if the problem began with my new internet connection or not, i guess it worked for a while even with new internet.

Btw i tried the public IP instead of domain name and no change.

Problem also is, that you have to do many tries and one of them eventually works...

0

If you have a route table that has routes to Internet Gateway, then associate the route table with your public subnet

0

Asking Amazon Q Free Tier with query "ssh operation timed out on ec2 instance", in my case:

I've identified several potential issues causing your SSH timeout:

Security Group Issue (Most Likely):

  • The security group does not have any inbound rules for SSH (port 22)
    Only allows traffic from within the same security group

Solution:

  • Add an inbound rule for SSH (TCP port 22) from your IP address

To resolve this:

Add an inbound SSH rule to your security group:

  • Protocol: TCP Port: 22
  • Source: Your IP address/32

Additional verification steps:

  • Ensure you're using the correct key pair ("<redacted>")
  • Verify you're using the correct username for your OS (appears to be <redacted>)
  • Check that your local IP matches the security group rule you'll add

enter image description here

enter image description here

enter image description here

enter image description here

1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.