Python Simplified

How to connect to an EC2 instance from Windows using PuTTy

connect to ec2 from windows

Introduction

If you have just started your cloud journey with AWS, one of the first tasks is to work with EC2 instances. And if you are using Mac OS or Linux distributions then you can SSH into EC2 using the terminal because macOS and Linux (Ubuntu, etc.) come with SSH client pre-installed.

However, if you are on Windows like me then you will have to use SSH clients to connect to the EC2 instance. There are many SSH clients such as PuTTy, BitVise, KiTTY, etc for Windows. But, Putty is the most popular and widely used software. 

In this article, we will launch an EC2 instance and then connect using Putty. You will also benefit from bonus tips at the end. 

Launching the EC2 instance

I hope that you already have an AWS account. So, log in to your AWS account open the EC2 console and Click on Launch Instances. 

Note that we will not go into details of every step as the main topic of this article is how to connect to EC2 instances from Windows using Putty. So, we quickly launch the Ec2 instance and then move to the next section.

launch ec2 instances

Step 1: Choose an Amazon Machine Image (AMI)

I would like to use Ubuntu AMI. So, I am going to search for Ubuntu and select Ubuntu Server 20.04 LTS (HVM) AMI and click on select.

step1-choose an amazon machine image

Step 2: Choose Instance Type

In the next screen, you need to select the instance type. We can go ahead with the default t2.micro which provides 1 CPU and 1 GB RAM. However, you can choose the instance according to your need. 

step2-choose instance type

Step 3: Configure Instance Details

In this screen, you can configure the instance as per your requirements. One important parameter I often use is ‘Number of instances’. This tells how many instances you want to launch at once. After adding other details click on Next to go to Add Storage section.

step3 configure instance details

Step 4: Add Storage

Next, you need to choose the size of the instance. By default, 8 GB will be provided. But you can select how much memory you need. 

step4-add storage

Step 5: Add Tags (optional)

Adding a tag is optional. You can skip this step altogether. Since we doing this demo for my website pythonsimplified.com, I have added the tags accordingly.

step5 add tags

Step 6: Configure Security Group

This is the most important step while launching the EC2 instance. A security group is a set of firewall rules that control the traffic for your instance. 

Since we are going to SSH into the EC2 instance make sure you have the SSH port opened as below. 

step6 configure security group

Step 7: Review Instance Launch

As the final step, you can review all the details you added so far and click on Launch

step7-review and launch

On the next screen, you will be asked to use an existing key pair or create a new key pair. We are going to select the ‘Create a new key pair’ option and name it ec2-demo as shown below.

Make sure to click on ‘Download the Key Pair’. This will download the private key for you which you will use SSH into EC2 instance. After downloading the key pair, click on Launch Instances.

step7-download key pair

You can see that the EC2 instance is up and running.

step8-ec2 running

Connect to EC2 instance using PuTTy

Next, download and install the Putty SSH client from here. You will notice that two apps PuTTy and PuTTygen are installed on your system. 

Convert .pem to .ppk

PuTTy will not work with the .pem file. The key pair file ec2-demo.pem which we downloaded in the previous section is the .pem file. This should be converted to .ppk format which PuTTy expects. The PuTTygen app helps us to convert the .pem to .ppk format.

Open the PuTTygen app and click on load. This will open another window. On this new window choose ‘All files (*.*)’ and then select ec2-demo.pem file.

putty step1 open puttygen

As soon as you open the file, you will see the below notification. Click ok. 

putty step2 - convert to ppk

Next, click on Save private key and you will be asked if you want to save them without a passphrase. You can select Yes and save the file in .ppk format. I saved it as ec2-demo.ppk.

putty step3 - save ppk

Connect to an EC2 instance

We have converted ec2-demo.pem to ec2-demo.ppk in the previous section. Now, let’s connect to the EC2 instance using this .ppk file. 

Open the PuTTy application. Next, you only need to provide two details: hostname and private key

Hostname format: <user-name>@<Public IPv4 DNS>
Ex: ubuntu@ec2–35–172–221–211.compute-1.amazonaws.com

putty step4 hostname

Next, expand SSH and click on Auth. Here will load the private key ec2-demo.ppk

putty step4 - load private key

That’s it. When you click on Open, you will be connected to an EC2 instance as you can see from the below screenshot. 

putty step4 - ec2 login

Bonus tip

If you are using the default parameters of Putty then after a few minutes of inactivity the terminal will get disconnected. You will have to log in again which is a real pain. 

You can avoid this by setting the below 2 parameters. These two configurations make sure that your terminal won’t disconnect often due to inactivity.

  • Seconds between keepalives = 5
  • Select ‘Enable TCP keepalives”
putty config

Conclusion

To connect to an EC2 instance, you need an SSH client and private key from AWS. Though there are many SSH clients available for Windows OS, PuTTY is the most popular and widely used. In this article, you understood how to use PuTTY to connect EC2 instances. I hope you liked the article and the bonus tip on how to keep PuTTY alive from frequent disconnection due to inactivity. 

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on email
Chetan Ambi

Chetan Ambi

A Software Engineer & Team Lead with over 10+ years of IT experience, a Technical Blogger with a passion for cutting edge technology. Currently working in the field of Python, Machine Learning & Data Science. Chetan Ambi holds a Bachelor of Engineering Degree in Computer Science.
Scroll to Top