How to run VSCodium + Remote-SSH with a FreeBSD (Bastille) jail

If you ever want to use VSCodium (or VSCode) to work on a project via Remote-SSH that is isolated in its own FreeBSD jail, you’ll run into the issue that FreeBSD isn’t officially supported by the VS Code server that gets deployed on the remote host.

Fortunately, there’s a solution. Remote-SSH works like this: your local editor connects over SSH and deploys a “server” (binaries + runtime) on the remote host to run extensions and services there.

Because that server is designed for Linux (glibc, filesystem layout, etc.), it fails on FreeBSD. We need to provide a “good enough” Linux via Linuxulator + linux_base-rl9 (Rocky Linux 9 under compat) — and that’s where FreeBSD’s magic comes in.

Step 1 — FreeBSD host: enable Linuxulator + Rocky Linux 9 base

On the host (not inside the jail), enable Linuxulator and install the RL9 base:

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

This is the minimum you need so the remote server has a modern Linux userspace.

Step 2 — Configure your Bastille jail

In the jail configuration (depending on your Bastille layout, typically at /usr/local/bastille/jails/MYJAIL/jail.conf), make sure you use devfs with ruleset 13 (there’s a story behind that) and enable the extra permissions you need for Linuxulator to work properly:

allow.sysvipc;
allow.mount;
allow.mount.devfs;
allow.mount.procfs;
allow.mount.linprocfs;
allow.mount.linsysfs;
allow.mount.tmpfs;

You’ll also need to mount the Linux-required filesystems (linprocfs, linsysfs, and devfs) inside the jail and use the host’s Linux base. Add the following to your jail’s fstab:

/compat/linux /usr/local/bastille/jails/MYJAIL/root/compat/linux nullfs ro 0 0
linproc /usr/local/bastille/jails/MYJAIL/root/compat/linux/proc linprocfs rw 0 0
linsys /usr/local/bastille/jails/MYJAIL/root/compat/linux/sys linsysfs rw 0 0
devfs /usr/local/bastille/jails/MYJAIL/root/compat/linux/dev devfs rw,ruleset=13 0 0

Step 3 — Configure your SSH client

The simplest trick to make Remote-SSH work is to force the remote command to be Linuxulator’s bash when you connect:

On your local machine, in ~/.ssh/config (or whatever config file you use for Remote-SSH):

Host MYJAIL
HostName your.host.or.ip
User youruser
RemoteCommand /compat/linux/usr/bin/bash

Extra option: switch the user’s shell to bash (Linuxulator)

Another, more direct option—if for some reason the RemoteCommand in the config doesn’t work (keeping in mind this will also affect your normal SSH shell)—is to change the jail’s SSH user shell to Linuxulator’s bash: /compat/linux/usr/bin/bash:

  1. Add that path to /etc/shells inside the jail (otherwise chsh may reject it).

  2. Change the user’s shell: chsh -s /compat/linux/usr/bin/bash youruser

With this, you’ll be able to use VSCodium without (major) issues on a project hosted on a FreeBSD server inside a jail.

Leave a Comment

Este formulario guarda los datos que indiques de nombre, email y comentario para poder realizar un seguimiento de los comentarios dejados en cada entrada.