How to connect to ports on a remote server through the encrypted SSH channel for windows?
Tags: aws, beginners, ssh, cloud
Published: 2022-11-22 11:57:51

# Introduction
- SSH tunnels allow you to securely connect to ports on the remote server.
- Without it, you wouldn't be able to connect to the remote server due to system firewall, or security group rules.
- In this post, you will establish an SSH connection with a tunnel from a port on your local system to another port on the remote server to access an EC2 Instance as an example.
- I'll explain this for windows, there are very simple differences for those who use Linux/macOS.


# Before we start
- Windows has no SSH client, so you must install one.
- This part will use PuTTY (freely available [here](http://www.putty.org) on their website) and a previously converted PEM key (converted to PPK using PuTTYgen).
- If you did't undrstand what is the PEM file and how we convert it to PPK using PuTTYgen, see this [blog](https://medium.com/@a00ayad00/what-is-the-compute-resources-and-how-to-create-an-ec2-instance-and-download-the-pem-file-to-3032fbd8642d) on medium websit or this [post](https://dev.to/aws-builders/explain-what-is-the-compute-resources-create-an-ec2-instance-and-download-the-pem-file-to-generate-the-ppk-key-pair-from-it-bf4) on dev websit



# Create an SSH connection using PuTTy

### Step 1
- Navigate to the EC2 Management Console and copy the **Public IPv4 address**.
- You can find the Public IP under the AWS EC2 console, and choosing the EC2 instance you want to access.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9e5myxaf78igsbiod3ki.jpg)

### Step 2
- Open PuTTY and insert the EC2 instance public IP Address in the **Host Name (or IP address)** field

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ih0igkgeyir9abyup2m0.jpg)

### Step 3
- Navigate to the **Connection** > **SSH** > **Auth** section.
- Browse to the location of the PPK key pair you downloaded earlier and select it.
- Click **open**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnbfl4wd0jltsn6viegl.jpg)

### Step 4
- Select **Tunnels** under the SSH menu item, Add a new forwarded port with the following values:

**Source port**: *8000*
**Destination**: *localhost:8888*
- Click **Add** to add the tunnel (it appears in the large text box once clicked as in the image below).
- Click **Open** to connect

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wetpe0wtprb248z5arr.jpg)

### Step 5
- After waiting a few seconds, the prompt (a black window) will be opened.
- Login as ec2-user and you will see the EC2 server welcome banner and be placed in the Linux shell.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzbjjunn1kbq5e5m5tdq.png)
<br><br><br>.



### ----------- Well Done 💚💙💜👌🏼💪🏼👏🏼👏🏼 -----------
- Now you are ready to send the first commands to your EC2 Linux instance.
- You can check the EC2 instance metadata, which is only available from within the instance itself.
- Instance metadata is data about your instance that you can use to configure or manage the running instance. This metadata can be extremely useful if you want to automate the setup of new instances.
- In order to obtain the instance metadata you will use the curl utility.
- cURL (Client URL) is a free, open-source project, and already loaded on your instance.
- cURL is a great way to transfer data using one of its supported protocols (such as HTTP).

##### Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9037exuse5zrhrlk1sy.png)

- You can get the public SSH key of the attached key pair using the public-keys metadata as the image bellow:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/020laqkjecw96vtuu5hg.png)

Have fun and thanks for reading ^.^

[GitHub](https://github.com/a00ayad00)
[LinkedIn](https://www.linkedin.com/in/a00ayad00)
[Facebook](https://m.facebook.com/a00ayad00)
[Medium](https://a00ayad00.medium.com/)