Skip to content

Instantly share code, notes, and snippets.

@varunagrawal
Forked from artificialsoph/jupyter_ngrok.md
Last active March 25, 2024 17:07
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 varunagrawal/130618c169fe2eca572ac84384c45b84 to your computer and use it in GitHub Desktop.
Save varunagrawal/130618c169fe2eca572ac84384c45b84 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 or TeamViewer.

If it's a new server, install Python (using pyenv) and jupyter.

pip install jupyter -y

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

jupyter notebook --generate-config
jupyter notebook password

Open the generated ~/.jupyter/jupyter_notebook_config.py and find and update the following settings

c.JupyterNotebookApp.allow_remote_access = True
c.ServerApp.open_browser = False

Now install ngrok using the instructions from the ngrok website. This is nice since it will use apt, homebrew or the package manager of your platform.

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