SSH tunneling explained

I had trouble for the longest time trying to do it - even after ekami’s amazing tutorial - thank you very much!

1 Like

For anyone who’s already able to ssh into an aws instance: here’s a quality of life script to save typing:

#!/bin/bash

IP = $1
SSHKEYPATH=$HOME/.ssh/your_key.pem

if [ -z "$2" ]
    then
        PORT=5913
else
    PORT=$2
fi

if [ -z "$1" ]
    then
        echo Error: IP Address Required.
        exit 1
fi

ssh -i $SSHKEYPATH ubuntu@$IP -L$PORT:localhost:$PORT

Make sure to replace your_key.pem with the actual ssh key you’ll use. Also don’t forget to set the script to executable via chmod +x sshaws.sh in terminal (make sure you use whatever name you save the script as).

Usage: place this script wherever you want and run it via
>>> ./sshaws.sh IPADDRESS PORT.
Port number is optional (default 5913 is from using a vnc screen sharer - set to whatever you like), but ip address is required. I added a condition so it won’t fail silently if you forget to pass it in.

You can then run an ssh jupyter notebook via jupyter notebook --no-browser --port=PORTNUM on the remote machine as you usually do.

1 Like

I am able to ssh the Paperspace on my mac, however the returned URL to open a jupyter notebook with my browser doesn’t work.

Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://psxxxxxxx:8888/?token=fc29523d4fc45ae621bbf4ded86c1c7e2c003e0960be8202&token=fc29523d4fc45ae621bbf4ded86c1c7e2c003e0960be8202

Any working solution?

1 Like

this was very helpful with my paperspace

start the jupyter in the paperspace using options --allow-root and --ip=0.0.0.0

and on my laptop i used the ssh tunnel like this (copy into a shell script and chmod +x for it)

LOCAL_PORT=“9000”
REMOTE_SERVER=“paperspace ip”
REMOTE_PORT=“8888”
TUNNEL_USER=“paperspace”
TUNNEL_HOST=“paperspace ip”

ssh -L $LOCAL_PORT:$REMOTE_SERVER:$REMOTE_PORT $TUNNEL_USER@$TUNNEL_HOST -N

run the above script, it will ask for the password, type that in, and it will keep running, close it after you are done with the exercise, else it will keep the port open, also dont forget to close out paperspace instance

and when i open browser to localhost:9000 it will open the notebook running on paperspace
this is so easy

1 Like

The link to this article changed to An Illustrated Guide to SSH Tunnels (solitum.net)