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, and might just makes things worst
UPDATE: It is not about permissions - i can log in normally just fine. I suspect it might be because of memory issues
For me it was the apache server hosted on a t2.micro linux EC2 instance, not the EC2 instance itself.
I fixed it by doing:
sudo su
service httpd restart
Building off
@ted.strauss
's answer, you can selectSSH
andMyIP
from the drop down menu instead of navigating to a third party site.If SSH access doesn't work for your EC2 instance, you need to check:
If you're using VPC instance (you've VPC ID and Subnet ID attached to your instance), check:
0.0.0.0/0
as Destination and your Internet Gateway as Target.On Linux, you may also check route info in System Log in Networking of the instance, e.g.:
where
UG
flags showing you your internet gateway.For more details, check: Troubleshooting Connecting to Your Instance at Amazon docs.
Just reboot the Ec2 Instance once you applied Rules
To connect use ssh like so:
Where
keyname.pem
is the name of your private key,username
is the correct username for your os distribution, andxxx.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
orroot
orubuntu
. 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.
To enable ssh access from the Internet for instances in a VPC subnet do the following: