VSCode server on MetaCentrum machines
When developing with VSCode in MetaCentrum, a straightforward setup like:
- project dir in
$HOME
dir - VSCode server running on frontend
- connection to frontend through VSCode remote development
can be far too resource-expensive.
Frontends are not computing nodes
Resource-expensive (CPU, mem) processes running on frontends may be killed without warning.
Therefore, we recommend another setup with the VSCode server running on a computing node within a standard job.
VSCode running on a computing node
- on your local station, generate a SSH key pair
ssh-keygen -f /home/username123/.ssh/my_key
- choose a port number between 7000 and 30000 (e.g. 26759) and add the following sections to
.ssh/config
on your local station
# frontend section
Host tarkil.metacentrum.cz # your favourite frontend, e.g. tarkil
Port 22 # keep standard port for ssh
PubkeyAuthentication no
# all other computing nodes
Host *.cerit-sc.cz *.fav.zcu.cz *.fzu.cz *.grid.cesnet.cz *.hw.elixir-czech.cz *.ibot.cas.cz *.ics.muni.cz *.metacentrum.cz *.meta.zcu.cz *.natur.cuni.cz *.nti.tul.cz *.ueb.cas.cz
Port 26759 # chosen port number
IdentityFile path_to_private_key # Path to private key from step 1
- within a job, setup direct connection to computing node for VSCode remote development
# make another (server-side) SSH key pair and store it in a scratch dir
mkdir -p "$SCRATCHDIR/.ssh"
chmod 700 "$SCRATCHDIR/.ssh"
rm -f "$SCRATCHDIR/.ssh/server_key" "$SCRATCHDIR/.ssh/server_key.pub"
ssh-keygen -f "$SCRATCHDIR/.ssh/server_key" -N "" -C "VSCode" -q -t ed25519
echo "SSH key generated"
# to $SCRATCHDIR/.ssh/authorized_keys, add public key from step 1
touch "$SCRATCHDIR/.ssh/authorized_keys"
chmod 600 "$SCRATCHDIR/.ssh/authorized_keys"
PUBKEY='ssh-ed25519 AAAAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3wN3+QgMAVJERjayo user123@PC'
grep -q "$PUBKEY" "$SCRATCHDIR/.ssh/authorized_keys" || echo "$PUBKEY" >> "$SCRATCHDIR/.ssh/authorized_keys"
echo "Public key added to authorized_keys"
# make sure that the chosen port is free
PORT=26759
netstat -tan |grep -q "0.0.0.0:$PORT " && { echo "port $PORT is busy" >&2; exit 1; }
# on the computational node, start running ssh server demon that listens on $PORT port
echo "Starting SSH server"
/usr/sbin/sshd -D -p $PORT -o "HostKey $SCRATCHDIR/.ssh/server_key" -o "PermitRootLogin no" -o "PasswordAuthentication no" -o "ChallengeResponseAuthentication no" &
echo "SSH running on $(hostname):$PORT"
echo "Connect to:" hostname
- Through VSCode remote development, connect to hostname and PORT.
Last updated on