Skip to content

Instantly share code, notes, and snippets.

@ma7dev
Last active February 8, 2023 12:57
Show Gist options
  • Save ma7dev/444473e113a815624edfa1647df32953 to your computer and use it in GitHub Desktop.
Save ma7dev/444473e113a815624edfa1647df32953 to your computer and use it in GitHub Desktop.
How to use a remote Jupyter notebook in VS code

To run access a remote jupyter notebook, you will need to do the following:

  1. Setting ssh config file (~/.ssh/config):
Host FLIP # access point server
    HostName access.engr.oregonstate.edu
    User ONIDusername
Host DGX # target server
    HostName submit-b.hpc.engr.oregonstate.edu
    User ONIDusername
    ProxyJump FLIP

Context: at OSU, FLIP server is our access point server and DGX server is a cluster server that I would like to access, so in order to access the DGX server, I would need to access the FLIP server first. The ProxyJump configuration states that if I want to access the DGX server, I would need to access the FLIP server first. This step is needed for VS code's extension, Remote - SSH, to have access to the DGX server.

Note: Steps 1.b-c and 2.b-c assuming the DGX server uses SLURM to manage jobs, so if your target server doesn't use SLURM, please skip them.

  1. Setting Port Forwarding

    a. Ssh to the DGX server

    b. Load SLURM using the following command: module load slurm

    c. Start a job using the following command: srun -A eecs -p dgx2 --gres=gpu:1 --pty bash (group=eecs, machine=dgx2, shell=bash), replace any flag value as needed

    d. Install ngrok and follow their setup (https://ngrok.com/)

    e. Start the ngrok server: ./ngrok http PORT, replace PORT with any port

    f. Copy the generated URL, for example https://ad32ef7ad45e.ngrok.io

  2. Setting the Jupyter's Kernel

    a. Ssh to the DGX server

    b. Load SLURM using the following command: module load slurm

    c. Access the node used in 1.c using this following command: ssh NODE (NODE is what is written in the left, e.g. dgx2-5)

    d. Access your conda/pip environment if needed

    e. Generate a Jupyter configuration file: jupyter notebook --generate-config

    f. Set Jupyter's configuration: echo "c.NotebookApp.allow_remote_access = True" >> ~/.jupyter/jupyter_notebook_config.py

    g. Start Jupyter's server: jupyter notebook --no-browser --port=PORT, replace PORT with the same PORT used in 1.e

    h. Copy the URL token parameter, for example ?token=...

  3. Connecting everything together! (in VS code)

    a. Install Remote - SSH VS code's extension

    b. Connect to the DGX server using Remote - SSH

    c. Open a Folder and select the folder of your project

    d. CTRL+SHIFT+P then type Jupyter: Specify local or remote ...

    f. Select Existing then paste ngrok's url + token parameter, for example https://ad32ef7ad45e.ngrok.io/?token=...


Props to Austin L. for sharing ngrok and Aayam S. for sharing how ngrok and jupyter notebook could be used together.

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