Tom
Tom

Reputation: 435

SSH Connection from MAC to Amazon EC2 not working

I am trying to connect to Amazon EC2 via:

ssh -i ~/.ssh/YOUR_KEYPAIR_FILE.pem ec2-user@YOUR_IP_ADDRESS

The terminal takes 1 or 2 mins and then prints:

ssh: connect to host XXX port 22: Operation timed out

Any ideas?

Upvotes: 3

Views: 7751

Answers (4)

Thomas Carpeggiani
Thomas Carpeggiani

Reputation: 156

  1. Login to AWS
  2. Go to the Instances section
  3. Click on the security group associated with your EC2 instance
  4. Down the bottom click on the inbound tab and then click edit

Create this rule

TYPE         SSH
PROTOCOL     TCP  
PORT RANGE   22  
SOURCE       Anywhere

You should now be able to connect to the instance on port 22 via ssh with your key.

Upvotes: 3

Craig Lewis
Craig Lewis

Reputation: 79

I had a similar problem. I checked all my networking time and time again from the ec2 instance all the way through the VPC and out to the internet. Security groups were allowing all sources through ports 22 and 80. My NACL was allowing the right permissions. I knew AWS was all ok yet everytime I went to try ssh into an instance I would still get an operation timeout, indicating that problem must be with my local machine instead.

First to check that the ssh port was open I ran the following:

ssh localhost

This worked fine!

Afte doing some research on the net, in the end it all boiled down to java and my terminal not recognising that java was installed on my machine.

Supporting Document: AWS Documentation

No Java means that your .pem will not be recognised

Start by running the follwing:

java -version

If you get no hits then install relevant java SDK for your OS and once installed run

which java

You should get something like this:

/usr/bin/java

Now we can try connect to an instance again and hopefully you should have success this time!

ssh -v -i ~/Downloads/labamikey.pem [email protected]

   __|  __|_  )
   _|  (     /   Amazon Linux AMI
  ___|\___|___|

[ec2-user@ip-10-0-0-54 ~]$

Upvotes: 1

apharna
apharna

Reputation: 11

Can you try changing permissions to YOUR_KEYPAIR_FILE.pem like this chmod 600 YOUR_KEYPAIR_FILE.pem

Then shoot the command ssh -i YOUR_KEYPAIR_FILE.pem ec2-user@YOUR_IP_ADDRESS

Upvotes: 1

Ryan Parman
Ryan Parman

Reputation: 6935

You need to open port 22 in your security group. All ports are closed by default.

Upvotes: 1

Related Questions