Setting up VSCode to work on the cluster
Visual Studio Code (VSCode) is general-purpose, freely available intergrated development environment. It is modular with extensions available for many different programming languages and file formats.
VSCode allows you to connect to the cluster from within the editor and work on your code directly on the cluster.
This section shows you how to set this up. It should work independent of whether you use VSCode on Windows, Linux or MacOS.
This functionality does not mean that you have to use VSCode. Other IDEs have similar functionality. If you want to use an IDE, you need to find the one best suited to your needs.
- 1 Preparations
- 1.1 SSH Keys
- 1.2 SSH config
- 1.3 Set up VSCode
- 1.4 Connecting with VSCode
Preparations
SSH Keys
The best way to connect to the through the cluster with VSCode is by using ssh keys. If you do not yet use ssh keys on the cluster, we recommend that first change your general connection the cluster to using ssh keys (see How to login to ALICE or SHARK ).
If you have already been using ssh keys to connect to ALICE, you can in principle use your existing ssh key or create a new one specific for using with VSCode.
SSH config
You should set up a separate ssh config file for VSCode, because VScode wants to have write access to the ssh config if you use the manual setup. In order to avoid accidentally overwriting anything else in your ssh config, it is best to use a separate ssh config.
We would recommend setting up the ssh config for VSCode in advance because this is easier when working with an ssh gateway
First, we create a separate ssh directory to put the config file. Open a terminal on your Linux or MacOS computer or open PowerShell if you are on Windows and run:
mkdir ~/.ssh_vscode
Next, create a file config
in the new directory. For simplicity, we can just open the file in VSCode from the command line (also PowerShell)
code ~/.ssh_vscode/config
Of course, you can use any other editor of your choice.
Now that the file is open, add host settings for at least one login node similar to what you have already done in your standard ssh config based on Login to ALICE or SHARK from Linux :
ALICE
Host alicegw
HostName ssh-gw.alice.universiteitleiden.nl
User <username>
ServerAliveInterval 60
IdentityFile ~/path/to/private/ssh/key
Host alice2vsc
HostName login2.alice.universiteitleiden.nl
User <username>
ProxyJump alicegw:22
ServerAliveInterval 60
IdentityFile ~/path/to/private/ssh/key
where you need to replace <username>
with your ALICE user name.
Replace ~/path/to/private/ssh/key
by the actual path to the ssh key that you want to use
You can also use another login node on ALICE.
SHARK
where you need to replace <username>
with your SHARK user name.
Replace ~/path/to/private/ssh/key
by the actual path to the ssh key that you want to use
You can also use another login node on SHARK.
If you are connecting from within the LUMC network, you do not need the ProxyJump setting for the host shark2vsc
Set up VSCode
First, you need to install an extension. Open VSCode and go to Extensions. Then search for the extension “Remote - SSH” ( https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh ) and install it.
After it was installed and activated, go to “Preferences -> Settings” and search for “remote.ssh”.
In the list of settings that has appeared, look for “Remote.SSH: Config File” (probably the first one in the list) and specify the full path to your ssh config, e.g., /home/<username>/.ssh_vscode/config
(Linux) or C:\Users\<username>\.ssh_vscode\config
(Windows) where “<username>” is your user name on your local workstation.
It is best to verify that VSCode can find your ssh config. Type either “F1” or go to “Help → Show All Commands” and type in “Remote-SSH: Open SSH Configuration File”. After hitting enter, it should show you a drop-down menu with the path to the ssh config that you just specified. When you click on it, it should open the file.
Connecting with VSCode
When the config file is set up correctly, you can type “F1” or go to “Help → Show All Commands” and search for “Remote-SSH: Connect to Host”. This should show you the host alias for VSCode that you have defined in your ssh config (e.g., “alice2vsc” or “shark2vsc”) as an option. If it does, hit enter and wait. VSCode will probably open a new window and initialize. This takes a few seconds and then it should show you in the bottom right corner that you are connected.
You can open folders on the cluster just like you would on your local workstation. If you open a git repository, then you can use the git workflow in VSCode.
Your local VSCode will remember that opened a folder on the cluster which allows you to quickly reconnect.