Connect HPC in Visual Studio Code Using SSH

Keren Xu


This note is about how to connect USC HPC in Visual Studio Code using SSH in windows setting.

VS Code already has a great post on remote connecting using SSH here. First step is to get the Visual Studio Code Remote - SSH extension, which help us to open folders on remote hosts with a running SSH server. We can interact with files and folders in VS Code environment.

The most confusing step is configure key authentication.

SSH public key authentication is a convenient, high security authentication method that combines a local “private” key with a “public” key that you associate with your user account on an SSH host. This section will walk you through how to generate these keys and add them to a host.

We can create a private key and a public key by using following codes:



$pubKey=(Get-Content "$PUBKEYPATH" | Out-String); ssh "$USER_AT_HOST" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '${pubKey}' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Before running these codes, check if your “private key” is in $HOME\.ssh and it is called The “public key” on the remote host is ~/.ssh/authorized_keys.

Since USC hpc requires two-factor authentication. VS Code should prompt you to enter password and DUO PUSH. When you did not see the prompt, enable remote.SSH.showLoginTerminal setting in VS Code. This option helps you see the terminal while connecting remotely so that you can complete two-factor authentication in terminal, otherwise terminal won’t appear. Also select Linux when VS Code is asking what the environment is on your remote host.

After connecting to HPC, HPC address will appear on the Status bar. You can always refer to here to see which host you are connected to.

Remote x11 extension can help enable X11 forwarding, but currently does not support two-factor authentication.