DEV Community

Establish an SSH connection using AWS EC2 instance


  • 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
Enter fullscreen mode Exit fullscreen mode

The -fN creates the tunnel in the background and the tells it to listen on all interfaces instead of only 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.


Top comments (0)