Visual Studio (VS) Code on O2
Visual Studio Code on O2
You can now use the Visual Studio (VS) Code Remote Development to connect from your local computer to O2. Once the connection is established, you will be able to use the resources allocated for your O2 Slurm job.
Before starting, please ensure you meet all the System Requirements.
Note for Windows users: Depending on how you have VSCode installed, you may need to follow a slightly different procedure than what is outlined below. If you are using WSL, and VSCode is installed into WSL, you can follow all instructions in this section as if you are a Linux/Mac OS machine. However, if your VSCode installation is installed “normally” (e.g., it exists as a standard Windows application that you’d normally double click, etc. to start), you will need to access a different .ssh
directory, which will usually live at %UserProfile%
(C:\Users\{Username}
). If you also have WSL installed, you can navigate to this directory by typing cd /mnt/c/Users/{Username}/.ssh
. If not, you should still be able to navigate to your %UserProfile%\.ssh
directory in Powershell, where you can also generate your SSH keys. You can read more about this arrangement in the VSCode documentation/blog.
SSH Keys
The first step is to set up SSH keys from your local machine to O2. This step is optional as VSCode should support password-based authentication. An example of how to set up SSH keys would be:
To create keys for connecting from your desktop to O2, run the following ssh-keygen command (or equivalent) on your desktop.
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/USERHOME/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /USERHOME/.ssh/id_rsa.
Your public key has been saved in /USERHOME/.ssh/id_rsa.pub.
The key fingerprint is:
a5:b5:38:73:b7:3c:a6:8a:1d:a8:bd:87:4e:be:33:21
You will then need to add the content of ~/.ssh/id_rsa.pub
from your local computer to the O2 file ~/.ssh/authorized_keys
On a Linux or Mac computer, you can use the command
ssh-copy-id -i $HOME/.ssh/id_rsa.pub user@o2.hms.harvard.edu
or alternatively copy your local file .ssh/id_rsa.pub
to O2 (!!! do not replace your O2 ~/.ssh/id_rsa.pub
place the temporary copy somewhere else !!!) and then add the content of the copied id_rsa.pub
file to your O2 ~/.ssh/authorized_keys
.
For example:
$ cat ~/temp_copy_of_my_id_rsa.pub >> ~/.ssh/authorized_keys
and finally remember to delete that temporary copy from O2 ( rm ~/temp_copy_of_my_id_rsa.pub
)
Make sure that your O2 $HOME and .ssh permissions are set correctly by executing
$ chmod 0600 ~/.ssh/authorized_keys
$ chmod 0700 ~/.ssh
and
$ chmod g-w /home/$USER
You can also set up SSH keys to be used within the O2 cluster following the instruction from How to Generate SSH Keys
VSCode Remote Extension
You will need to install the VSCode Remote Extension - https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh - and if you want the extension pack https://aka.ms/vscode-remote/download/extension
Local SSH Configuration
The final step is to create an entry in your local SSH configuration file ~/.ssh/config
to be used with VSCode. This configuration needs to be done in your computer not O2. Windows users should see the above note for configuration nuances.
Inside the file ~/.ssh/config
you need to add the lines:
Where the resources allocated for the VSCode are specified within the ProxyCommand
line (default: 4GB of memory RAM, priority partition, and 3 hour of wall-time).
IMPORTANT: Increase the Connect Timeout on VS Code to allow time to receive the DUO push notification.
Enter > in the VS Code search bar.
Type: Remote-SSH: Settings.
Set the Remote.SSH: Connect Timeout option to 600.
How to start a VSCode Remote Extension using an O2 job
Enter > in the VS Code search bar.
Type: Remote-SSH: Connect to Host
Select: O2job
You will receive a DUO push notification
In the lower right corner, you will see the following information box
Click on “details” to view more informationThis step can take a few minutes until resources are allocated for your VS Code job on O2.
IMPORTANT: Once you are done, please click on
Close Remote Connection
to properly close and finish the Slurm job on O2.File → Close Remote Connection
O2 Portal VSCode Application
We also provide an Open OnDemand application to run VSCode entirely on O2 via the O2 Portal interface O2Portal - Visual Studio Code App