How to Connect to an EC2 Instance from a Windows Laptop


Amazon Elastic Compute Cloud (EC2) is a popular cloud computing service that allows you to run virtual servers in the cloud. If you're new to AWS or need a refresher, this guide will walk you through the steps to connect to your EC2 instance from a Windows laptop.
Prerequisites
Before you begin, make sure you have:
An AWS account with an active EC2 instance running
The key pair (.pem file) you used when launching the instance
Administrator access on your Windows laptop
The public IP address or DNS name of your EC2 instance
Step 1: Convert Your .pem Key to .ppk Format
Windows typically uses PuTTY for SSH connections, which requires the private key in .ppk format rather than the .pem format provided by AWS.
Download and install PuTTYgen from the official website
Open PuTTYgen
Click "Load" and select your .pem file (make sure to select "All Files" in the file type dropdown)
Click "Save private key" and save it as a .ppk file (you can ignore the warning about saving without a passphrase)
Step 2: Download and Install PuTTY
Download PuTTY from the same website
Run the installer and complete the installation
Step 3: Connect to Your EC2 Instance Using PuTTY
Open PuTTY
In the "Host Name" field, enter:
ec2-user@your-instance-public-ip
(Replace "your-instance-public-ip" with your actual public IP and "ec2-user" with the appropriate username for your AMI - typically "ec2-user" for Amazon Linux, "ubuntu" for Ubuntu, etc.)
In the left sidebar, navigate to:
Connection > SSH > Auth
Click "Browse" and select your .ppk file
(Optional) Go back to "Session" in the left sidebar, enter a name under "Saved Sessions", and click "Save" to store these settings for future use
Click "Open" to initiate the connection
If this is your first time connecting, you'll see a security alert - click "Yes" to continue
Alternative Method: Using Windows Subsystem for Linux (WSL)
If you prefer using native SSH:
Enable WSL on your Windows machine:
Open PowerShell as Administrator
Run:
wsl --install
Restart your computer
Open your WSL terminal (Ubuntu by default)
Navigate to the directory containing your .pem file
Set proper permissions:
chmod 400 your-key.pem
Connect using:
ssh -i "your-key.pem" ec2-user@your-instance-public-ip
Troubleshooting Common Issues
Connection timed out:
Verify your instance is running
Check your security group rules (should allow SSH on port 22 from your IP)
Verify the public IP address
Permission denied:
Ensure you're using the correct username for your AMI
Verify your key pair is correct
Check file permissions on your key file
Server refused our key:
Double-check you're using the correct key pair
Verify the key was properly converted to .ppk format
Security Best Practices
Always use SSH key pairs instead of passwords
Regularly rotate your key pairs
Restrict SSH access to only necessary IP addresses in your security group
Consider using AWS Systems Manager Session Manager for a more secure alternative to direct SSH
Conclusion
Connecting to your EC2 instance from a Windows laptop is straightforward once you've set up PuTTY with your converted private key. Whether you choose PuTTY or WSL, you now have the tools to securely access and manage your cloud servers.
For more advanced scenarios, you might want to explore using AWS Session Manager or setting up SSH config files for easier access to multiple instances. Happy cloud computing!
Subscribe to my newsletter
Read articles from Sdeep directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Sdeep
Sdeep
๐ Hello! I'm passionate about DevOps and I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together!