Friday, 14 April 2017

How to Connect to EC2 Instance using PuTTY and Terminal

1_connect to instanceIn our last post, we learned how to create EC2 instance in AWS. After successfully launching our EC2 Linux instance, today we will connect to our instance so we can install and run WordPress. There are two methods via which we can connect to our Amazon EC2 Linux instance:
  1. A standalone SSH Client
  2. A Java SSH client directly from my browser (Java required)
2_standaloneinstance
Later seems easy to connect as most of the computer have java installed, let's get started and see how to connect our EC2 instance directly from browser.
First check whether you have java installed or your browser supports java or not?
chrome not supportted
All of you have encountered with error/problem while connecting to your instance in Chrome browser as the Chrome browser version 42 and above disabled the standard way their browser supports plugin.
firefox_java not supported
Now it’s Firefox turn: While trying on Mozilla Firefox 64-bit, I got a message saying it is 64-bit and will not run java. Another failed attempt.
win10_edge_java not supported
Our Last hope?: Using Microsoft Edge browser didn’t help either as it doesn’t have support plugin. My bad!
Old is Gold!? While checking for java on internet explorer (IE11), a pop-up window appeared mentioning “the page you are viewing uses java”. Finally a positive response, now it’s time to connect our instance  by
  1. Sign-in to AWS console –> EC2 dashboard-> running instance-> select running instance –> click on Connect button
  2. Select “A Java SSH client directly from my browser (Java required)”
  3. Your username will be mentioned by default as “ec2-user”. Now enter the location of private key path (which you have downloaded in step 7 of creating ec2 instance) C:\folder\location\private_key.pem and select save key location
  4. Now click on “Launch SSH client” button .
IE not connecting


Wait! Nothing happened, the same pop-up appeared and didn’t connect. Looks like IE 11 on 64bit Windows 10 won’t work.

firefox-32bit limited support for plugin

This time around installing and running on  32-bit Firefox, I have had encountered with a different message (gladly) but – Limited support for the plugin, therefore will not run java.  There are other browser options like opera, safari which I didn’t try and leaving up to you to try it using above steps and leave a comment below whether they worked for you or not.

It’s time to go with the first option of connecting instance via standalone SSH client:

Connect to Amazon EC2 Linux Instance using PuTTY

For Windows user
  1. Download PuTTY, PuTTYgen

    PuTTYgen

  2. Open PuTTYgen –> click “Load” button –>  Windows explorer will open browse to the .pem file location (private key that you have downloaded while creating EC2 instance) and select “All Files (*.*)” otherwise you won’t be able to see your .pem –> click “open”

    PuTTYgen_2

  3. Select “save private key”. PuTTYgen warning window appear to ask you to save this key without a passphrase key? If you want to then you may choose otherwise it’s not necessary. In short press “yes” and save the .ppk file.

    PuTTY Alert


    PuTTY_hostname

  4. Now start PuTTY and enter hostname username@public_dns_name. e.g. ec2-user@52.xx.xxx.xxx48 or ec2-user@ec2-xx-xxx-xxx-xxx.us-west-1.compute.amazonaws.com
    (The username may vary depending on which AMI you have installed. You may find this information in example when you click Connect button in console) –> Connection type SSH and port 22

    PuTTY_auth


  5. In Category pane, expand connection, then expand SSH, click on Auth –> Browse your .ppk and click Open.

    PuTTY Alert-auth

  6. If you connect for the first time, PuTTY display security alert –> choose “Yes”.

    puTTY_login_success
  7. Connected!


For Mac OSX/Linux User:


EC2 Connect via Terminal
  1. Open Terminal

  2. Locate your private key (.pem) key. (In my case, private key is in download folder)

    cd ~/Downloads

  3. Your key must not be publicly viewable for SSH to work. Use this command:

    chmod 400 your_privatekey.pem

    or

    chmod 400 /location/private_key.pem

  4. Now connect to your instance using below command:

    ssh -i "your_privatekey_name.pem" ec2-user@ec2-52-xx-xxx-xxx.us-west-1.compute.amazonaws.com You will see message like this:
    The authenticity of host xxx:xxx:xx:xx:xx can't be established.
    RSA key fingerprint is xx:xx:xx:xx:x:xx:xx:xx:xx:xx:xx:xx:xx:xx
    Are you sure you want to continue connecting (yes/no)?


  5. Type Yes and enter

  6. Now you are successfully connected your EC2 Linux instance using Terminal.
On next, we will see how to install WordPress in AWS.

0comments:

Post a Comment