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.
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
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.
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.
Click the Load button, then find your .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.
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).
You should be presented with the PuTTY Configuration dialog.
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:
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.
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.
Now let’s click the “Open” button to open the SSH connection to the server.