DEV Community

alok-38
alok-38

Posted on

Connecting to an EC2 instance (server) on AWS using SSH from the windows power shell

SSH into an AWS EC2 Instance from the windows power shell

This guide shows how to connect to an AWS EC2 instance using SSH from Windows PowerShell and optionally configure the same setup for WSL so you can work seamlessly with VS Code.

Prerequisites

  • An AWS EC2 instance running

  • The EC2 public IP address

  • Your .pem key file downloaded

  • OpenSSH installed (available by default on modern Windows)

Step 1: Configure SSH on Windows

Open the SSH config file located at:

C:\Users\alok\.ssh\config
Enter fullscreen mode Exit fullscreen mode

🔁 Replace alok with your Windows username.

Open the file using Notepad or any text editor and add the following configuration:

Host ec2-dev
    HostName 98.93.224.136
    User ec2-user
    IdentityFile ~/.ssh/DevOps.pem
    Port 22
    IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

Notes

  • Host ec2-dev is an alias—you can name it anything.

  • Replace 98.93.224.136 with your EC2 instance’s public IP.

  • Make sure the .pem file path is correct and the file exists.

Step 2: Connect Using PowerShell

  1. Open Windows PowerShell as Administrator
  • Press Ctrl + X, then select Windows PowerShell (Admin)
  1. Run the following command:
ssh ec2-dev
Enter fullscreen mode Exit fullscreen mode
  1. When prompted to confirm the host fingerprint, type yes and press Enter.

🎉 You are now connected to your EC2 instance.

(Optional) Configure SSH for WSL & VS Code

If you use WSL and want to open the EC2 instance directly in VS Code:

  1. Open a new PowerShell or Windows Terminal

  2. Enter WSL:

wsl
Enter fullscreen mode Exit fullscreen mode
  1. Edit the SSH config file inside WSL:
vim /home/alok/.ssh/config
Enter fullscreen mode Exit fullscreen mode

🔁 Replace alok with your Linux username inside WSL.

  1. Add the same SSH configuration used in Windows:
Host ec2-dev
    HostName 98.93.224.136
    User ec2-user
    IdentityFile ~/.ssh/DevOps.pem
    Port 22
    IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

Now you can use:

ssh ec2-dev
Enter fullscreen mode Exit fullscreen mode

from WSL and open the session directly in VS Code using the Remote SSH extension 🚀

Final Tips

  • Ensure your .pem file permissions are correct

  • Your EC2 security group must allow inbound SSH (port 22)

  • Keeping the same alias across Windows and WSL avoids confusion

Top comments (2)

Collapse
 
avinashwagh profile image
Avinash wagh

As a Software Engineer currently learning Linux (Ubuntu) and planning to move into AWS next, this guide is extremely helpful. The step-by-step SSH setup from Windows and WSL makes the process very clear and practical. Thanks for sharing such well-explained content.

Collapse
 
alok38 profile image
alok-38

Thank you.