Skip to content
hero
Philippe Bordron

How to use the VSCode extension Remote-SSH with the cluster

VSCode remote-ssh on compute node diagram

Goal

Deport VSCode on a compute node and set limits to CPU and RAM usage

The extension Remote-SSH uses ssh to launch an instance of VSCode on another computer, and then the VSCode on your computer communicates with the one launched on the cluster.

We will configure a ssh alias in order use a compute node (through slurm) instead of the login nodes when using this extension.

Note

This tutorial uses VSCodium, which is a telemetry free version of VSCode.

Create a ssh alias

On our personal computer, we edit the file ~/.ssh/config as following (click on (1) to get a comment):

  1. A comment
~/.ssh/config
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Host genobioinfo-vscode # (1)!
    ForwardAgent yes # (2)!
    StrictHostKeyChecking no # (3)!
    UserKnownHostsFile=/dev/null
    ProxyCommand ssh -l %r genobioinfo.toulouse.inrae.fr "/usr/bin/srun -J vscode-ssh --mem=1G --cpus-per-task=1 --time=8:00:00 --pty /bin/bash -c 'socat - TCP:localhost:22'" # (4)!
    User <login> # (5)!

Host genobioinfo-vscode-huge # (6)!
    ForwardAgent yes
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null
    ProxyCommand ssh -l %r genobioinfo.toulouse.inrae.fr "/usr/bin/srun -J vscode-ssh-huge --mem=16G --cpus-per-task=4 --time=8:00:00 --pty /bin/bash -c 'socat - TCP:localhost:22'"
    User <login>
  1. Define an alias name we will use with VSCode, here genobioinfo-vscode.
  2. Forward to cluster our ssh keys (optional).
  3. This line and the next are used to avoid breakdowns if nodes are reinstalled.
  4. Here we configure the connection to a node when VSCode will connect to the cluster. We use srun to create a job that will run socat to forward the ssh exchanges to the job itself.
  5. The login to use to connect. Replace <login> with your cluster login.
  6. You can create other aliases with different slurm parameters according to your needs.

Save those modifications and run following commands on your computer to test the configuration:

# From your computer, connect to cluter by using the `genobioinfo-vscode` aliasssh genobioinfo-vscodePseudo-terminal will not be allocated because stdin is not a terminal.
srun: job 123456789 queued and waiting for resources
srun: job 123456789 has been allocated resources
srun: error: ioctl(TIOCGWINSZ): Inappropriate ioctl for device
srun: error: Not using a pseudo-terminal, disregarding --pty option
Warning: Permanently added 'genobioinfo-vscode' (ED25519) to the list of known hosts
# We are now connected to a compute node and we check ithostnamen001exit

If you get something similar to that, you are ready to use the Remote-SSH extension in VSCode.

Install Remote-SSH

  1. Click on the Extension tab on the left side of VSCode.
  2. Search for Remote - SSH in extensions. You can use following extension ids depending your editor flavor:
  3. Check the extension editor if multiple results.
  4. Click on install button.

After installation, a new tab on left side must have appeared.

Remote-SSH installation

Connect to the cluster

  1. Click on the Distant Explorer tab on the left side of VSCode. List of alias from ~/.ssh/config file must appear.
  2. Click on folder like icon on the right side of the genobioinfo-vscode alias. A new VSCode window must appear and after few seconds you must be connected. Alternatively, you can right-click on alias to choose to connect in a new or in the current window.
  3. You can check that our are connected by looking at the bottom left of VSCode window. You can see the text SSH: genobioinfo-vscode (or any alias name you used for connection)
  4. You can check the node you are connected by opening a Terminal in VSCode with menu Terminal -> new terminal,
  5. and type command hostname in it. You must get the node name. If you get genobioinfo1 or genobioinfo2, something get wrong.

Connect to cluster Check hostname

Manage timeouts

If the cluster is overloaded by many users, you will get a message similar to this one: Timeout Message

You can increase the time before failure this way:

  1. Go in Extensions Tab on the left.
  2. Click on the Manage button (the clog wheel). A menu appears.
  3. Click on the option Parameters in it.
  4. Set a higher value in field "Connect Timeout", for example 300 seconds.

Extends Timeout Extends Timeout

Go to workspace

  1. Go to Explorer tab on the left side.
  2. Click on Open folder
  3. Navigate to your project folder with the menu at the top of the editor
  4. Trust the authors.

Go to workspace Valid to workspace

Now you are in your workspace.

Next time you will go to the Remote Explorer tab (on the left side), you will be able to connect directly to this workspace.

Next time

Disconnect

  1. Click on the text SSH: genobioinfo-vscode at the bottom left of VSCode window. It opens a menu on the top of VSCode.
  2. Click on Close the remote connection.

Disconnect

Restore your bash terminal

You can restore your usual bash environment in the integrated terminal by editing your settings.json in such a way (source):

~/.config/VSCodium/User/settings.json
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  ..., 
  "terminal.integrated.profiles.linux": {
  "bash (login)": {
    "path": "bash",
    "args": ["--login"]
    }
  },
  "terminal.integrated.defaultProfile.linux": "bash (login)",
  ...
}