ℹ️ Overview In this section, we’ll establish SSH connections to both EC2 instances and verify network connectivity. We’ll use Visual Studio Code with the Remote-SSH extension for a modern development experience.
There are several ways to connect to EC2 instances. You can follow the instructions to connect to EC2 using PuTTY. In this lab, we will use Visual Studio Code to establish the connection.
Download Visual Studio Code

Install Remote-SSH Extension

Access the EC2 page

In the Connect to instance dialog
💡 Tip: The command format is:
ssh -i "aws-keypair.pem" ec2-user@<public-ip-address>

Navigate to Key Pair Directory
cd /path/to/your/keypair
Set Key Pair Permissions (Linux/Mac only)
chmod 400 aws-keypair.pem
⚠️ Security Note: AWS requires the key pair file to have restricted permissions (read-only for owner) before it can be used for SSH connections.

Connect via SSH in VS Code
F1 or Ctrl+Shift+P to open the command palette
Verify Connection

Test the internet connection by pinging a public IP:
ping 8.8.8.8 -c5
✅ Expected Result: You should receive 5 successful ping responses, confirming internet connectivity.

💡 Connection Architecture:
Your Computer → SSH → EC2 Public (via public IP)
↓
SSH → EC2 Private (via private IP)
Get EC2 Private IP Address

Test Connectivity from EC2 Public to EC2 Private
ping <EC2-Private-IP> -c5
✅ Expected Result: Successful ping responses confirm network connectivity between the instances.

ℹ️ Why Transfer the Key? EC2 Private doesn’t have a public IP, so we can’t SSH directly from our computer. We need to SSH from EC2 Public to EC2 Private, which requires the key pair file to be on EC2 Public.
Download PuTTYgen - RSA and DSA key generation utility as puttygen.exe
Download PSCP - SCP client for secure file copy as pscp.exe
Convert PEM to PPK Format (Windows only)

Save as PPK Format

Confirm Key Conversion

Upload Key to EC2 Public using PSCP
pscp -i aws-keypair.ppk aws-keypair.pem ec2-user@<EC2-Public-IP>:/home/ec2-user/
💡 Command Breakdown:
-i aws-keypair.ppk: Authentication key for PSCPaws-keypair.pem: File to uploadec2-user@<IP>: Target user and host:/home/ec2-user/: Destination directory
Upload Key using SCP (Linux/Mac alternative)
scp -i aws-keypair.pem aws-keypair.pem ec2-user@<EC2-Public-IP>:/home/ec2-user/
Verify Key Upload
ls -la

Set Key Permissions
chmod 400 aws-keypair.pem
🔒 Security Requirement: AWS requires key files to have restricted permissions (read-only for owner) before they can be used for authentication.

SSH to EC2 Private
ssh -i aws-keypair.pem ec2-user@<EC2-Private-IP>

Test Internet Connection
ping amazon.com -c5
❌ Expected Result: The ping will fail or hang because EC2 Private has no route to the internet yet.

💡 What’s Next? In the next section, we’ll create a NAT Gateway to enable outbound internet access for EC2 Private while maintaining security by blocking inbound connections from the internet.
🏗️ Current Architecture:
⚠️ Keep Connection Open: Leave your SSH session to EC2 Private open so you can verify internet connectivity after creating the NAT Gateway in the next section.