Aidan Pfister
2 min readJun 29, 2021

Connecting to an AWS EC2 Instance Through PuTTY and Performing Basic Python

This is a good exercise to become familiar with basic AWS and Python.

Assuming you have an AWS account and a user set up, we are going to spin up an Ubuntu 20.04 t3.small EC2 instance.

Name your key pair, and download the file to your pc.

Putty is not compatible with the .pem file that AWS provides, so we need to use the PuTTYgen tool to convert it to a .ppk file. I have used the default settings, and just loaded in a private key file, and then saved the new generated ppk to my pc.

Now, we open up PuTTY, paste the public IPv4 for your EC2 instance. Click the auth option, and load up the key. Now you just connect, insert your username, and you’re in!

You should see this or something similar upon successful connection

Next up, we will create a Python virtual environment. We will create a new directory titled “environment”.

In the new directory, run the following command:

python3 -m venv ~/environment/

If it has run correctly, your environment directory should be populated with new files.

We will now create and execute a very basic “Hello World” program.

In your terminal, run the following command:

vim hello.py

Assuming you know how to navigate and use vim, we will type in this line:

print("Hello, world!")
This is what it should look like inside of vim.

Exit out of vim, then run this final command:

python 3 hello.py

You should receive the following output:

Congratulations! Now we have successfully connected to an EC2 instance through PuTTY, and executed basic Python.

This was a great learning experience for me to understand AWS and how to use EC2 instances, as well as creating and using Python virtual environments.

Aidan Pfister

I am a student currently learning about the cloud and linux.