Skip to content

Set up VS Code on OpenMind compute node (Method 02)

H Gazula edited this page Feb 12, 2024 · 9 revisions

This page describes an alternative method to connect to the compute node on Openmind without having to note down the node name every time as described here. Using this method, you don't even have to log on to Openmind first. Everything can be done from your local machine.

Prerequisites:

a. https://github.mit.edu/MGHPCC/OpenMind/wiki/Configuring-password-less-SSH-login

One Time

  1. On your local machine create a script named tunnel.sh (or whatever name you prefer) with the following contents (please feel free to change resources according to your requirements).
#!/bin/bash
#SBATCH --job-name="tunnel"
#SBATCH --time=8:00:00     # walltime
#SBATCH --output="tunnel.out"
#SBATCH --error="tunnel.err"
#SBATCH [email protected]
#SBATCH --mail-type=BEGIN

/usr/sbin/sshd -D -p 2222 -f /dev/null -h ${HOME}/.ssh/id_rsa # uses the user key as the host key

NOTE: The private key file id_rsa could be whatever you named it to in your machine.

  1. Create another script named script.sh (or whatever name you prefer) with the following line.
sbatch tunnel.sh
  1. Open the ${HOME}/.ssh/config file on your local machine and add the following lines
Host openmind-node   # name it whatever you want
    ProxyCommand ssh openmind "nc \$(squeue --me --name=tunnel --states=R -h -O NodeList) 2222"  # see note below
    StrictHostKeyChecking no
    User hgazula  # of course, please change this to your user name
    IdentitiesOnly=yes
    PreferredAuthentications publickey
    PasswordAuthentication no
    IdentityFile ~/.ssh/id_rsa  # id_rsa should be replaced with your private key file name is

NOTE (Important):

  • The first part of ProxyCommand should be the same command you use to connect to openmind. For some of you, it may be ssh {username}@openmind.mit.edu or however you configured it in your config file. In my case, it is ssh openmind.
  • Notice the --name=tunnel is the job name specified in the tunnel.sh file.

Every time (you want to connect to openmind)

  1. Open a terminal (vscode or wherever) and run cat submit.sh | ssh openmind "bash -s" (Once again, ssh openmind is how I connect to openmind and should be replaced with how you connect)
  2. Now go to VSCode and connect to the openmind-node and you should be on the compute node.

Final notes:

  1. Note that you may not have access to the compute node as soon as you run the cat submit.sh | ... command. Hence, I added the following lines in tunnel.sh to notify me when the job began (i.e. when the node is available) so step 2 doesn't fail.
#SBATCH [email protected]
#SBATCH --mail-type=BEGIN
Clone this wiki locally