VS Code at ACCRE

From ACCRE Wiki

Prerequisites

One-time setup

  • Add the following lines to your local ssh config (e.g. ~/.ssh/config). Note, insert your ACCRE username/VUNet ID for the instances of <VUNet ID>:
Host hpc
  ControlMaster auto
  ControlPath ~/.ssh/master-%r@%h:%p
  HostName login.accre.vu
  User <VUNet ID>

Host hpcx
  ProxyCommand ssh hpc "nc \$(squeue --me --name=tunnel --states=R -h -O NodeList,Comment)"
  StrictHostKeyChecking no
  User <VUNet ID>
  • On the cluster, add the following sbatch script to your home directory (~), and name it e.g. 'tunnel.sh'. Note, adjust the sbatch script based on the partition, account, qos, and cpu/memory requirements you want for your session. The following is an example of requesting 2 cores and 4G of memory per cpu core in the interactive partition for the fe_accre_lab_int account and the fe_accre_lab_int QOS. Reminder, you can view your user account resources for ALL partitions by running the 'slurm_resources' command:
#!/bin/bash

#SBATCH --output="tunnel.log"
#SBATCH --job-name="tunnel"
#SBATCH --time=12:00:00     # walltime
#SBATCH --account=fe_accre_lab_int #account
#SBATCH --partition=interactive #partition
#SBATCH --qos=fe_accre_lab_int #qos if using interactive or interactive gpu partitions
#SBATCH --cpus-per-task=2  # number of cores
#SBATCH --mem-per-cpu=4G   # memory per CPU core


# find open port
PORT=$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')
scontrol update JobId="$SLURM_JOB_ID" Comment="$PORT"
# start sshd server on the available port
echo "Starting sshd on port $PORT"
/usr/sbin/sshd -D -p ${PORT} -f /dev/null -h ${HOME}/.ssh/id_ed25519
  • In your local terminal generate an ssh key if you don't have it already, then type 'ssh-copy-id hpc', which copies to your local public key to the cluster. How to generate ssh key
  • In a terminal on the cluster, also generate an ssh key if you don't have it already. Depending on which signature algorithm you use (ed25519, ecdsa, rsa, etc.), update the last line in the tunnel.sh script to point to the correct key type. For example, ${HOME}/.ssh/id_ecdsa instead of ${HOME}/.ssh/id_ed25519.

Every time you connect / start your day

  • In your local terminal, do ssh hpc . Once logged in, type sbatch tunnel.sh to start the remote server. Keep this terminal window open throughout the day to avoid having to re-authenticate, but do not use it for any compute-intensive tasks!
  • Open VSCode and connect to your projects using Remote Explorer with the ssh target hpcx.
  • You can also connect to the HPC through other terminal windows by typing ssh hpcx.