Skip to content

Instantly share code, notes, and snippets.

@ma7dev
Last active May 7, 2025 21:21
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.

@mrharrison007
Copy link

This command seems to have disappeared "Jupyter: Specify local or remote", I'm not sure you can connect current VS Code and current Jupyter extension to a remote jupyter kernel, etc.

@ma7dev
Copy link
Author

ma7dev commented May 6, 2025

Yeah. I can confirm that they have removed this option. However, here is another way:

CTRL+SHIFT+P then type Notebook: Select Notebook Kernel > Select Another Kernel > Existing Jupyter Server > enter your ngrok's url

@mrharrison007
Copy link

No such animal, "Notebook: Select Notebook Kernel", maybe my extensions are wrong.
image

VS Code 1.99.3

Extensions:
Jupyter
Identifier: ms-toolsai.jupyter
Version: 2025.3.0

@mrharrison007
Copy link

I wasn't sure what VS Code server did, apparently that's the way to go for my use case and possibly why remote access functionality is degraded or non-existent from the VS Code client.

Use case: Headless Ubuntu Server with GPUs.

Thanks!

@ma7dev
Copy link
Author

ma7dev commented May 7, 2025

Your issue is that you need to open the notebook, then follow the instructions at the top to see this option. This should fix your issue.

@mrharrison007
Copy link

mrharrison007 commented May 7, 2025

Thank will try, and the VS Code Web App via VS Code Server --> does not support Github Copilot as of this writing.

@mrharrison007
Copy link

You got me going man, I've been banging my head on this one. Many thanks, let me know if I can help you in any respectful way!

@ma7dev
Copy link
Author

ma7dev commented May 7, 2025

Glad it helped! Just keep helping others along your way 🙏

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