How to SSH into an AWS ECS container server with PuTTY on Windows

Sometimes you’ll need to SSH into an EC2 server instance that hosts your ECS/Docker containers. Below are the steps I took to do so.

REFERENCES USED

Prerequisites

You will need to have/do the following before you begin:

  • You must have the Public IP address (or public DNS name) of the EC2 server that is hosting your ECS container
  • PuTTY must be installed on the Windows-based machine you are using to connect to the EC2 server
  • You must have the .pem file that contains your private SSH key, which was generated when you created your AWS keypair
  • You must have enabled access to port 22 when you created your ECS Cluster; OR you must have manually opened access to port 22 in the security group used by your ECS Cluster

IMPORTANT

If you don’t have the .pem file for your keypair, then you’re out of luck. AWS only gives you one chance to download the .pem file when you create the keypair.

sshwpow-screenshot-01
Find the link to your EC2 instance here…
sshwpow-screenshot-02
You’ll need the Public IP address from here
sshwpow-screenshot-03
Security Group explicitly allows incoming connections on port 22

PuTTY Setup

Converting Your Private Key Using PuTTYgen

Start by launching the PuTTYgen utility. You’ll use this to convert your .pem file into a format that can be used by PuTTY.

sshwpow-screenshot-04

sshwpow-screenshot-05

Click the Load button, then find your .pem file

sshwpow-screenshot-06

sshwpow-screenshot-07
This is what you should see after opening the .pem file

Now click the “Save private key” button to save the key in PuTTY’s .ppk format. It will prompt you to decide if you want to add a passphrase. I prefer not to use a passphrase.

sshwpow-screenshot-09

We are done with PuTTYgen, so you can close the utility now.

Starting a PuTTY Session

Start the PuTTY application from the Windows Start Menu (or any other way you wish).

sshwpow-screenshot-10

You should be presented with the PuTTY Configuration dialog.

sshwpow-screenshot-11

In the Host Name field, you need to enter the value in <username>@<ipaddress> format, as shown below. The username “ec2-user” is what the AWS instructions said to use for my EC2 instance type. So for my EC2 instance, I’ll use the value:

ec2-user@35.153.23.143

sshwpow-screenshot-12

Now you need to associate your .ppk file with this target server. In the tree on the left-hand side, find the “Connection” category, and expand the “SSH” option. Click on the “Auth” option. Finally, click the “Browse…” button and provide the location of your .ppk file.

sshwpow-screenshot-13

Now click on the “Session” category in the tree. Provide a name for this session configuration, then click the “Save” button. This will allow you to reuse this configuration again in the future.

sshwpow-screenshot-14

Now let’s click the “Open” button to open the SSH connection to the server.

sshwpow-screenshot-15

sshwpow-screenshot-16
And we’re in!

 

 

Leave a Reply