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
.pemkey file downloadedOpenSSH 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
🔁 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
Notes
Host
ec2-devis an alias—you can name it anything.Replace
98.93.224.136with your EC2 instance’s public IP.Make sure the
.pemfile path is correct and the file exists.
Step 2: Connect Using PowerShell
- Open Windows PowerShell as Administrator
- Press
Ctrl + X, then select Windows PowerShell (Admin)
- Run the following command:
ssh ec2-dev
- 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:
Open a new PowerShell or Windows Terminal
Enter WSL:
wsl
- Edit the SSH config file inside WSL:
vim /home/alok/.ssh/config
🔁 Replace alok with your Linux username inside WSL.
- 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
Now you can use:
ssh ec2-dev
from WSL and open the session directly in VS Code using the Remote SSH extension 🚀
Final Tips
Ensure your
.pemfile permissions are correctYour EC2 security group must allow inbound SSH (port 22)
Keeping the same alias across Windows and WSL avoids confusion
Top comments (2)
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.
Thank you.