DEV Community

Establish an SSH connection using AWS EC2 instance

Introduction

  • Before starting, see my previous post from here
  • SSH tunnels allow you to connect to ports on a remote server through the encrypted SSH channel.
  • This allows you to securely connect to ports on the remote server that you otherwise wouldn't be able to because of system firewall, or security group rules.
  • In this post, you will establish an SSH connection with a tunnel from port 8000 to port 8888 on the remote server.
  • This tunnel will allow you to connect from instance public IP to the Jupyter notebook server.

Establish an SSH connection

Step 1

Connect to your EC2 Instance:

Image description

Image description

Step 2

Enter the following command and press Enter:

ssh -i key.pem ubuntu@localhost -fN -L 0.0.0.0:8000:127.0.0.1:8888
Enter fullscreen mode Exit fullscreen mode

The -fN creates the tunnel in the background and the 0.0.0.0 tells it to listen on all interfaces instead of only 127.0.0.1/localhost so you can connect from the public IP

Step 3

Enter yes to establish the connection:

Image description

Now, you connected to the remote server and established an SSH tunnel to forward a port on the remote server.



GitHub
LinkedIn
Facebook
Medium

Top comments (0)