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 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 on medium websit or this post 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.
Step 2
- Open PuTTY and insert the EC2 instance public IP Address in the Host Name (or IP address) field
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.
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
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.
----------- 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:
- You can get the public SSH key of the attached key pair using the public-keys metadata as the image bellow:
Have fun and thanks for reading ^.^
Top comments (0)