You now have a server instance running on EC2.  It is time to connect and take it for a spin.  Ssh is a UNIX tool for connecting to servers.  If you are on a Mac or Linux machine, then you already have ssh installed.  We will look at them first, and then explore using the similar putty application on Windows.

Before you begin, locate your key file that was downloaded during setup.  This is a file with a .pem extension.  For these steps, I will assume a file name of myKey.pem.  You also need to know the IP address of your instance or the elastic IP you assigned to it.


Opening the Required Port to Connect

You also need to ensure the ssh port is open on your server.

  1. Log in to the AWS Management Console
  2. Go to the EC2 Dashboard
  3. Click on the instances menu.  Now, select the instance you want to work with
  4. In the Description tab at the bottom of the page, find the Security groups item.  Click on the group name
  5. You will see the security group screen.  Now, select the Inbound tab at the bottom of the page.
  6. Click on the edit button
  7. Select “Add Rule”
  8. Select SSH from the drop down.  Verify the port is 22, and the protocol is TCP.  Enter your local address for the tightest security.  Otherwise, leave it open to all.  It can be secured at a later time.  More information about this is provided in the “Further Reading” section below

 

Mac/Linux

  1. The file must have read only access so issue the command:
    chmod 400 myKey.pem
  2. Now use the file to connect :
     ssh -i myKey.pem [email protected]
  3. The IP address can be used, if you prefer
     ssh -i [email protected]
  4. You will be presented with the instance console like this:
    Last login: Mon Jun 20 15:07:44 2016 from c-69-137-134-29.hsd1.tn.comcast.net
           __|  __|_  )
           _|  (     /   Amazon Linux AMI
          ___|\___|___|
    https://aws.amazon.com/amazon-linux-ami/2016.03-release-notes/
    [[email protected] ~]$

 

Windows (Putty)

Create a private key that Filezilla can use.

https://rb-sns.com
  1. Download Putty from the putty page: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. You will need putty.exe and puttygen.exe (if the link does not work you can always do a search for “putty download” and it should be towards the top of the list.
  2. Run puttygen.exe
  3. In the type of key parameters select SSH-2 RSA
  4. Click Load, you will have to change the dropdown to All Files (*.*) in order to find your .pem file
  5. Browse to your file and select it, click open and click ok
  6. Click Save private key, Click yes to save without a passphrase.
  7. Save to a name and the file will be created with a .ppk extension

Now we can connect to our server…

  1. Open the Putty application (double-click the icon)
  2. Enter the IP address of your instance in the hostname field but precede it with “[email protected]”.  For example, [email protected] for an IP address of 122.22.45.298
  3. Click on the plus by SSH on the menu and then click on Auth
  4. Select browse.  Now find the .ppk file you just created.
  5. Click on Session
  6. Enter a name in the saved sessions text.  Then, click on the save button
  7. Now when you open putty the next time you can select the session name to load all of this information
  8. Click on Open
  9. You will see a command line window open and are now connected to your instance.

Get the Latest Security Updates

If you have not logged in recently or this is your first time you might see a notice to run the update.  This will help keep your server running the latest system software.  Go ahead and type

sudo yum update

to get the latest updates and install them.  Just type y when it asks if you want to continue. This is similar to the Microsoft Windows update feature (if you are familiar with it).  Updates to applications on the server are regularly updated to ensure your server is safe and secure.

Click here to return to the class


Further Reading

There is a lot of power that putty and ssh have that have not been covered here.  These first books are a great source of details about these tools and navigating the complex aspects of security and connecting to your servers.

SSH Mastery: OpenSSH, PuTTY, Tunnels and Keys

SSH, The Secure Shell: The Definitive Guide

You can also check out a good SSH Tutorial at https://support.suso.com/supki/SSH_Tutorial_for_Linux

[sgmb id=1]

 

Rob Broadhead

Rob is a founder of, and frequent contributor to, Develpreneur. This includes the Building Better Developers podcast. He is also a longtime student of technology as a developer, designer, and manager of software solutions. Rob is a founder and principle of RB Consulting and has managed to author a book about his family experiences. In his free time, he stays busy raising five children (although a few have grown into adults). When he has a chance to breathe, he is on the ice playing hockey to relax.

Leave a Reply