Skip to main content

Visual Studio Code Remote Connection

Visual Studio Code is arguably the most popular code editor right now, but given its User Interface, it's not as straight-forward to use in remote systems as Vim, Nano, or other popular, command-line editors.

It's possible, though, to configure VSCode to establish a remote connection to a host, and navigate its file system as if it was in the local machine, making it possible to develop code comfortably with its GUI.

caution

Visual Studio Code Remote explorer doesn't work on machines with ARM architecture, such as the Huawei cluster, due to incompatibility.

Installing required extensions

To be able to develop remotely using VSCode you need at least the two following extensions, developed by Microsoft themselves:

Remote - SSH

Allows you to establish remote connections to machines and navigate through them. Doesn't do much by itself, and is not necessary to connect via SSH from a Terminal in a VSCode tab, since that uses the system's SSH client.

Remote - SSH extension

Remote Explorer

This is the extension that actually allows you to open remote directories and files, to edit them from your local machine. It can't function properly without the Remote - SSH extension.

Remote Explorer extension

This assumes you have an SSH client installed, in case you don't, you can install OpenSSH for Unix-based distributions:

DistributionCommand
Debian/Ubuntusudo apt install openssh-client
OpenSUSEsudo zypper install openssh
Arch/Manjarosudo pacman -S openssh
Fedorasudo dnf install -y openssh-clients

For Windows systems, you can install Putty and configure it.

Setting up your .ssh/config

~/.ssh/config is a very useful file that allows you to add different options to your SSH client. For example, forcing the use of the -X option to enable Direct X forwarding, or multiple other configuration setting. This is important because VSCode takes the list of accessible hosts from the SSH config files. Below is an example of an entry:

Host                    gpp2
HostName glogin2.bsc.es
User bscXXXYYY

This allows you to type ssh gpp2 instead of ssh bscXXXYYY@glogin2.bsc.es, to begin a connection to the second MN4 login node.

  • Host should contain any alias you may want to use, multiple entries are allowed, separated by blank spaces.
  • Hostname is the actual name of the login node.
  • User is the username with which you access the machine.

You can find more information here.

Connecting

Once you are done with the configuration, your Remote Explorer tab should look something like this. You can then pick whichever to start a connection, then select Linux as the host's operating system. The first connection may take a couple of minutes, so be patient.

Remote Explorer hosts