How to Connect to an EC2 Instance from a Windows Laptop

SdeepSdeep
3 min read

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:

  1. An AWS account with an active EC2 instance running

  2. The key pair (.pem file) you used when launching the instance

  3. Administrator access on your Windows laptop

  4. 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.

  1. Download and install PuTTYgen from the official website

  2. Open PuTTYgen

  3. Click "Load" and select your .pem file (make sure to select "All Files" in the file type dropdown)

  4. 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

  1. Download PuTTY from the same website

  2. Run the installer and complete the installation

Step 3: Connect to Your EC2 Instance Using PuTTY

  1. Open PuTTY

  2. 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.)

  3. In the left sidebar, navigate to:

     Connection > SSH > Auth
    
  4. Click "Browse" and select your .ppk file

  5. (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

  6. Click "Open" to initiate the connection

  7. 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:

  1. Enable WSL on your Windows machine:

    • Open PowerShell as Administrator

    • Run: wsl --install

    • Restart your computer

  2. Open your WSL terminal (Ubuntu by default)

  3. Navigate to the directory containing your .pem file

  4. Set proper permissions:

     chmod 400 your-key.pem
    
  5. Connect using:

     ssh -i "your-key.pem" ec2-user@your-instance-public-ip
    

Troubleshooting Common Issues

  1. 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

  2. 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

  3. 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

  1. Always use SSH key pairs instead of passwords

  2. Regularly rotate your key pairs

  3. Restrict SSH access to only necessary IP addresses in your security group

  4. 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!

0
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!