Test Connection
Checking the Connection
- Download Visual Studio Code

- Go to the EC2 page
- Select Instances from the left navigation menu
- Select the EC2 Public instance
- Select Connect

- In the Connect to instance panel
- Select the SSH Client tab
- Copy the SSH command from the Example section
- Note: you’ll need to replace the path to your key pair file

- In Visual Studio Code
- Open Extensions (Ctrl+Shift+X)
- Search for and install the Remote - SSH extension
- This extension lets you connect via SSH directly from VS Code

- Connect via SSH from Visual Studio Code
- Open a terminal in VS Code (Ctrl+`)
- Navigate to the folder that holds your key pair file:
cd /path/to/your/keypair/folder
- Run the SSH command (replace
<public-ip> with the Public IPv4 address of EC2 Public):
ssh -i "aws-keypair.pem" ec2-user@<public-ip>

- Check the internet connection on EC2 Public
- Once the SSH connection succeeds, run a ping command:
- You should see responses confirming EC2 Public has internet connectivity

Connect to the EC2 Private Server and Check Its Internet Connection
- Get the private IP of EC2 Private
- Go to the EC2 console
- Select Instances
- Select EC2 Private
- In the Details tab, note the Private IPv4 address

- Test connectivity from EC2 Public to EC2 Private
- From the terminal already connected via SSH to EC2 Public
- Run a ping to the private IP of EC2 Private:
ping <EC2-Private-Private-IP> -c5
- A successful result confirms network connectivity between the two instances


💡 Preparing to SSH into EC2 Private
- Download the tools needed to transfer the key pair
- EC2 Private has no public IP, so we can’t SSH into it directly from our own machine
- We need to copy the key pair file to EC2 Public so we can SSH from there into EC2 Private
- Download the following tools into the same folder as your key pair:
- Convert the key pair to PPK format
- Run puttygen.exe
- Click Load

- Load the PEM file and convert it
- Select the aws-keypair.pem file
- Click OK on the success message
- Click Save private key
- Save it as aws-keypair.ppk

- Finish converting the key
- Confirm that aws-keypair.ppk has been created
- This file will be used with PSCP

- Upload the key pair to EC2 Public
- Open Command Prompt (Windows) or Terminal (Mac/Linux)
- Navigate to the folder containing PSCP and the key pair
- Run the following command (replace
<EC2-PUBLIC-IP> with the public IP of EC2 Public):
pscp -i aws-keypair.ppk aws-keypair.pem ec2-user@<EC2-PUBLIC-IP>:/home/ec2-user/

- Get the public IP of EC2 Public
- Go to the EC2 console
- Select the EC2 Public instance
- In the Details tab, copy the Public IPv4 address


- Confirm the file was uploaded
- Go back to the SSH terminal connected to EC2 Public
- Run
ls to list files:
- You should see the aws-keypair.pem file in the folder

- Set permissions on the key pair file
- AWS requires the key pair file to have restricted permissions
- Run:
chmod 400 aws-keypair.pem
- This ensures only the owner has read access to the file

- SSH into EC2 Private from EC2 Public
- Use the private IP of EC2 Private:
ssh -i aws-keypair.pem ec2-user@<EC2-Private-Private-IP>
- Type
yes when prompted about the fingerprint
- You’ve now successfully connected to EC2 Private!

- Check the internet connection from EC2 Private
- Try pinging out to the internet:
- ⚠️ Result: The ping will FAIL because EC2 Private doesn’t have a NAT Gateway yet
- In the next step, we’ll create a NAT Gateway so EC2 Private can access the internet

💡 Connection Architecture Summary:
- Your computer → SSH → EC2 Public (via public IP)
- EC2 Public → SSH → EC2 Private (via private IP)
- EC2 Private → ❌ Internet (no NAT Gateway yet)