How to connect to EC2 instance5 min read


An Amazon Elastic Compute Cloud (EC2) instance is a virtual server that runs applications on the Amazon Web Services (AWS) infrastructure. In this tutorial, we will learn how we can connect to the EC2 instance.

AWS is a robust and ever-evolving cloud computing platform, while EC2 is a service that enables company subscribers to run application programs in a computing environment. The EC2 will host an almost infinite number of virtual machines.

To meet customer needs, Amazon offers a variety of instances with different CPU, memory, storage, and networking resource configurations. Each type is also available in two sizes to accommodate varying workloads.

You can connect to your AWS EC2 instance in one of the following ways,

  1. Using PuTTY
  2. Using Git Bash

Connect to EC2 instance using PuTTY

PuTTY is a terminal emulator, serial console, and network file transfer program that is free and open-source. SCP, SSH, Telnet, rlogin, and raw socket connections are among the network protocols it supports. Click here to download PuTTY. Once done, install it. After the installation is complete, you will find PuTTY and PuTTYgen are installed. PuTTYgen is used to generate keys.

Now, to connect to your ec2 instance using PuTTY, you need to have a .ppk file. When you create an ec2 instance on AWS, a .pem file is downloaded. We need to convert the .pem file to a .ppk file and using this, connect to our instance through PuTTY. Follow the below steps to create a .ppk file from a .pem file,

Note: The bellow steps are on assumption that you have already downloaded the .pem file

1. Open PuTTYgen

2. Click on Load

Tutorial on how to connect to EC2 instance

3. Select All files option

4. Open the .pem file

5. Click on OK

6. Click on Save private key

7. You will get a warning message asking you to save the key without a passphrase. Click on Yes.

8. Provide the name and location for the file and click on Save.

We have successfully generated a .ppk file from a .pem file. Now we will use this .ppk file to connect to our ec2 instance.

1. Open PuTTY

2. Provide the public IP address of your ec2 instance in the Host Name section

3. On the left menu, expand SSH and click on Auth

4. Click on Browse and open the .ppk file

5. Click on Open. You will get a warning message again. Click on Yes

6. Provide the username as per your instance

Done. We have successfully connected to our AWS ec2 instance using PuTTY.

Connect to EC2 instance using Git Bash

Git Bash is a program that adds an emulation layer to Microsoft Windows environments, allowing users to use Git command-line. It’s similar to a kit that installs some basic bash utilities on a Windows computer. It provides a command-line interface on Windows that enable us to use all Git features as well as most basic UNIX commands. Click here to download Git Bash. After completion, install it and then follow the below-mentioned steps to connect to your AWS ec2 instance,

Note: If you are using a Linux system, then you can follow the below steps using terminal. No need to install PuTTY or Git Bash.

1. Right-click on windows home screen and select Git Bash Here.

2. Execute the below command to connect to your aws instance,

ssh -i <path_to_pem>/<pem_file_name.pem> [email protected]<public_ip>

In the above command, after -i parameter, you need to give the path where your .pem file is saved with the .pem file name. After this, the username of your instance (if you have created an ubuntu instance, the username will be ubuntu) with the public IP of your AWS instance. You can find the public IP in the AWS console as below,

Give this IP while connecting to the instance. Refer to the below screenshot,

Tutorial on how to connect to EC2 instance

As you can see from the above screenshot, we have successfully connected to the AWS ec2 instance using Git Bash.

Note: If you have created a Linux instance, then the username will be ec2-user and the same should be given in the ssh -i command.


Leave a Reply