Connect Visual Studio Code to FreeBSD remote servers

Visual Studio Code’s native SSH remote explorer connection is more than just an SSH tunnel — it needs to be able to execute some Linux binaries on the remote server in order for all of the fancy functionality to work.

When connecting to a FreeBSD server, VSCode may fail to connect and give you errors like:

[] > Unsupported platform: FreeBSD
> exitCode==35==
> osReleaseId==freebsd==
[] Failed to parse remote port from server output
[] Terminating local server
[] > local-server-1> ssh child died, shutting down

Luckily, getting VSCode connecting to FreeBSD isn’t tough.

How to connect VSCode to a FreeBSD remote server

First, on the FreeBSD server, enable Linux compatibility mode, and then install the Linux base core.

sudo sysrc linux_enable="YES"
sudo service linux start
sudo pkg install linux_base-c7

Then, on the machine you’re using VSCode on, edit .ssh/config and add these lines for the FreeBSD server’s entry.

Host xxx
  Hostname xxx
  RemoteCommand /compat/linux/usr/bin/bash
  RequestTTY force

Finally, find the Enable Remote Command setting in VSCode and enable it.

Voila! Head on over to the remote explorer and connect to the server. You’ll now be able to interact with the FreeBSD remote just like it was a Linux host, with all the helpful functionality in VSCode that you’re used to.

It took a long time to figure this one out. Credit to Mateusz Kwiatkowski and Oliver Giersch for the helpful comments I stumbled upon which explained the missing parts of this process.