Skip to content

Instantly share code, notes, and snippets.

@IamAdiSri
Last active April 5, 2019 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IamAdiSri/a1588f9aab89a3ad08311b3d1fe18951 to your computer and use it in GitHub Desktop.
Save IamAdiSri/a1588f9aab89a3ad08311b3d1fe18951 to your computer and use it in GitHub Desktop.
Remote Jupyter Notebook - Server to Client Reverse Tunneling Script
#!/bin/bash
if [ $# -lt 2 ] ; then
echo "jp.sh <port on server> <port n local>"
echo "example: sh jp.sh 8686 8989"
echo "jp.sh <port on server> <port on local> <local ip> <user name>"
echo "example: sh jp.sh 8686 8989 10.x.x.x username"
exit 1
fi
if [ $# -ge 3 ]; then
lip="$3"
else
lip="10.x.x.x" #default IP of your choice
fi
if [ $# -ge 4 ]; then
uid="$4"
else
uid="username" #default username of your choice
fi
(cd ~ && jupyter notebook --no-browser --ip=0.0.0.0 --port="$1" > mylog 2>&1 &)
echo "jupyter notebook started on server port $1"
echo "Port forwarding. $uid @ $lip server port:$1 local port:$2"
ssh -N -f -R "$2":localhost:"$1" "$uid"@"$lip"
echo "open 'localhost:$2' in browser"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment