Skip to content

Instantly share code, notes, and snippets.

@artificialsoph
Last active March 27, 2024 06:29
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save artificialsoph/443a8bf9af3302df9cb0cb54a616f838 to your computer and use it in GitHub Desktop.
Save artificialsoph/443a8bf9af3302df9cb0cb54a616f838 to your computer and use it in GitHub Desktop.
Quickest way to get Jupyter notebook running on a remote server.

Log into your server with ssh, something like

ssh -i "my_secret.pem" ubuntu@12.123.12.123

If it's a new server, you'll need to install a few things.

Install conda with

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Now install jupyter with

conda install jupyter -y

To use jupyter, we need to modify a few settings and create a password:

jupyter notebook --generate-config
echo "NotebookApp.allow_remote_access = True" >> ~/.jupyter/jupyter_notebook_config.py
echo "NotebookApp.open_browser = False" >> ~/.jupyter/jupyter_notebook_config.py
jupyter notebook password

Now install ngrok:

wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
unzip ngrok-stable-linux-amd64.zip

Ngrok let's us easily create tunnels between our remote machine and the web. Now we have everything we need to run jupyter and connect to it.

In the next part we'll need two separate terminals connected to our remote because once we run jupyter, it will occupy a window with logging. You can either open a second terminal and ssh into it again, or you can use a tool like tmux to manage them within a single terminal.

In one, we will start jupyter like always

jupyter notebook

In in the other, we'll connect ngrok

./ngrok http 8888

and you'll see

ngrok by @inconshreveable

Tunnel Status                 online
Version                       2.0/2.0
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://92832de0.ngrok.io -> localhost:8888
Forwarding                    https://92832de0.ngrok.io -> localhost:8888

Connnections                  ttl     opn     rt1     rt5     p50     p90
                              0       0       0.00    0.00    0.00    0.00

Navigate to the forwarding address listend and Jupyter should be working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment