Using VSCode with the Hub#
Pre-requisites#
⭐ LEAP Pangeo Access
You must have the ability to start a server on LEAP Pangeo. More information about membership can be found in the Membership page.
⭐ Websocat
websocat must be installed on the client machine.
pip install websocat
works on Mac OS, and pre-built binaries are available
for all other operating systems.
⭐ VSCode
VSCode must be installed on the client machine.
⭐ VSCode Extensions
Find and install the Remote-SSH and Jupyter extensions on the VSCode Extensions Marketplace.
Remote-SSH will be used to connect to your LEAP Pangeo server, while the Jupyter extension will be used to open .ipynb notebooks and manage the kernel that runs your code on the remote server.
Before you begin
There are two levels of authentication – your JupyterHub token and your SSH key pair (public/private). This guide will walk you through both so you can connect with JupyterHub from your VSCode without entering a password.
The JupyterHub token is like a temporary password that lets your local machine talk to the JupyterHub server over a special channel (via websocat).
The JupyterHub token will be included in your ~/.ssh/config
file on your local machine so ssh knows how to talk to the server.
Your SSH key pair is like a secure ID card. Your local machine holds the private key (secret), and the server holds your public key (the badge that proves it trusts you).
The SSH public key will be added to your GitHub account for convenience, and then downloaded onto the JupyterHub server (saved into ~/.ssh/authorized_keys
) so the server knows your local machine is trusted.
1 [Web Browser] Start your server#
This setup only works after you start your JupyterHub server. So, start your server! Please keep in mind that even after setting up Remote-SSH on your VSCode, you would have to start your server on LEAP Pangeo before attempting to connect to the server.
2 JupyterHub Token Setup#
2-1 [Web Browser] Obtain a JupyterHub Token#
We will need to create a JupyterHub token for authentication.
Go to the JupyterHub control panel. You can access it via
File -> Hub control panel
in JupyterLab, or directly going to https://leap.2i2c.cloud/hub/token.In the top bar, select Token.
Create a new Token, and keep it safe. Treat this like you would treat a password to your JupyterHub instance! It is recommended you set an expiry date for this.
2-1 [Local Terminal] Configure local ~/.ssh/config
with the JupyterHub Token#
We will set up our ssh config file to tell ssh
how to connect to our JupyterHub. Add
an entry that looks like this to the end of your ~/.ssh/config
file (create it if it does not exist).
Host leap.2i2c.cloud
User jovyan
ProxyCommand websocat --binary -H='Authorization: token <YOUR-JUPYTERHUB-TOKEN>' asyncstdio: wss://%h/user/<YOUR-JUPYTERHUB-USERNAME>/sshd/
replace:
<YOUR-JUPYTERHUB-TOKEN>
with the token you generated earlier<YOUR-JUPYTERHUB-USERNAME>
with your jupyterhub username
3 SSH Key Pair Setup#
3-1 [Local Terminal] Generate a ssh key pair#
Generate the key pair on local terminal by executing the command:
ssh-keygen -t ed25519 -C "your_email@example.com"
Make sure to replace your_email@example.com with your actual email address.Add key to ssh-agent by executing:
eval "$(ssh-agent -s)"
andssh-add #~/.ssh/id_ed25519
Copy the public key: Use following command to show the public key on your local machine:
cat ~/.ssh/id_ed25519.pub
And copy the entire key, including the email address.Do not expose your private key
id_ed25519
- the private key should not be shared.
3-2 [Web Browser] Save the public key on Github#
Go to Github key settings, then click on “New SSH Key.”
Paste the copied public key (including email address) into the “Key” box, and save. In the next step, we will leverage Github to save your public key on JupyterHub.
3-3 [Web Browser] Setup ssh keys on your JupyterHub server#
Make sure your JupyterHub server is still running. If not, start a new one.
Open a terminal in JupyterLab on your web browser
Run the following commands:
mkdir -p ~/.ssh wget https://github.com/<YOUR-GITHUB-USERNAME>.keys -O ~/.ssh/authorized_keys chmod 0600 ~/.ssh/authorized_keys
replacing
<YOUR-GITHUB-USERNAME>
with your github username.Verify that authorized_keys contains your key by running
cat ~/.ssh/authorized_keys
on the JupyterLab TerminalIf it is empty or nonexistent, then create the file authorized_keys in the ~/.ssh/ directory and paste your ssh public key (
cat ~/.ssh/id_ed25519.pub
, from local terminal) and save file.
With that, we are ready to go!
4 [Local Terminal] Try ssh
-ing into your JupyterHub!#
After all this is setup, you’re now able to ssh in! On your local terminal, try:
ssh leap.2i2c.cloud
and it should just work! If configured correctly, leap.2i2c.cloud
should not ask you for a password.
Attention
Debugging Help
If you get the error ssh: connect to host leap.2i2c.cloud port 22: Operation timed out
, then check you have installed websocat by running run pip install websocat
and confirm that ther config file in the correct directory, ~/.ssh/config
If the CLI asks for a password, please verify that your access token and public keys are valid and consistent across platforms and try the previous steps again. Keep in mind this test has to only work once, and it is not necessary to ssh into JupyterHub via CLI once you confirm this works once.
5 [VSCode] Connect to LEAP Pangeo on VSCode#
Launch VSCode, click on the top search bar to open the Command Palette (cmd + shift + P on Mac)
Enter
>Remote-SSH: Add New SSh Host
Enter
ssh leap.2i2c.cloud
Click on the first option, /Users/<your_local_username>/.ssh/config
Follow further prompts until you are connected. You should see this on your top bar once you are connected.
Click on “Open Folder” and select the home directory. You should be able to access your LEAP-Pangeo Notebooks remotely now.
6 [VSCode] Write / execute your code via a remote kernel#
Once you open a Notebook, you will find a selection menu for a kernel on the top-right.
Select the option “Python Environments”
Selected the recommended
conda (Python 3.x.x)
kernel
You should now be good to execute code via remote kernel on the LEAP server from local VSCode!
7 [VSCode] Re-connecting to Remote SSH After Setup#
Type
>Remote-SSH: Connect to Host
into the top search bar.
Select
leap.2i2c.cloud
. Keep in mind this action will only work if the 2i2c Server is already active.
Repeat the steps from “Write / execute your code via a remote kernel”
Contributors to this documentation:
Yuvi [yuvipanda], jupyter-sshd-proxy:
Joe Ko [jk4730@columbia.edu], clarifications on how to setup the local public key
Sungjoon Park [sp4050@columbia.edu], whom you can contact for questions regarding this workflow