Remotely connect jupyter lab through ngrok
date
Aug 10, 2023
slug
tool1
author
status
Public
tags
tools
summary
type
Post
thumbnail
updatedAt
Sep 30, 2023 11:37 AM
Introduction
With the increasing prevalence of remote work, SSH is commonly used to connect to servers. However, SSH does not support forwarding Jupyter Lab, which is a popular IDE for data science. Surprisingly, I recently discovered that we can easily use ngrok to forward requests to the local server port, allowing remote access to Jupyter Lab. In this document, I will share a step-by-step procedure for setting up ngrok to access Jupyter Lab. The server system used in this guide is Ubuntu 22.04.
Setting Up
There are two main steps for setting up: 1. Installing and setting up ngrok, and 2. Changing the Jupyter Lab configuration. Let's get started!
Installing and Setting Up ngrok
- Go to https://ngrok.com/, sign up, and log in to your account.
- Install ngrok on your Ubuntu system by running the following command:
snap install ngrok
- Connect ngrok to your account. You can find your token on the setup and installation subpage of the website. Run the following command:
ngrok config add-authtoken {your own token}
- Launch ngrok with the Jupyter Lab port:
ngrok http {jupyter lab port}
After completing these steps, you may still encounter a "forbidden" error when trying to access Jupyter Lab. This is because Jupyter Lab does not allow remote control by default. The next step is to change the Jupyter Lab configuration.
Changing the Jupyter Lab Configuration
- By default, Jupyter Lab does not create a config file during installation. Therefore, we need to create a default config file by running the following command:
jupyter lab --generate-config
- Add the default setting in
/.jupyter/jupyter_notebook_config.py
:
echo "NotebookApp.allow_remote_access = True" >> ~/.jupyter/jupyter_notebook_config.py
- Launch Jupyter Lab:
jupyter lab
Accessing Jupyter Lab
After completing the above steps, go back to your remote PC and visit the HTTPS address provided by ngrok. Then, enter the token and enjoy!
