Skip to content

Instantly share code, notes, and snippets.

@mateuszkwiatkowski
Last active January 3, 2026 07:25
Show Gist options
  • Select an option

  • Save mateuszkwiatkowski/ce486d692b4cb18afc2c8c68dcfe8602 to your computer and use it in GitHub Desktop.

Select an option

Save mateuszkwiatkowski/ce486d692b4cb18afc2c8c68dcfe8602 to your computer and use it in GitHub Desktop.
Configure FreeBSD to work with VScode's remote ssh extension

This procedure was tested on FreeBSD-CURRENT build from d8819d88af52.

  1. Enable linuxulator and install linux userland:

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

    Test it:

    $ /compat/linux/usr/bin/uname -a
    Linux monster-1 4.4.0 FreeBSD 14.0-CURRENT #1 main-n254392-d8819d88af52: Wed Apr  6 22 x86_64 x86_64 x86_64 GNU/Linux
    

    For more details on linuxulator setup please refer to handbook.

  2. remote-ssh seem to ignore bash config files so we need to change $PATH in /etc/login.conf or send custom env with SetEnv directive in ssh_config. Choose which fits you better.

    Confiugure /etc/login.conf

    By default it's class default, we need to give priority to linux binaries: :path=/compat/linux/usr/sbin /compat/linux/usr/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin:\ rebuild CAP database: cap_mkdb /etc/login.conf

    Or add this to your ssh config (~/.ssh/config)

    Host your-freebsd.box
      SetEnv PATH="/compat/linux/usr/sbin:/compat/linux/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
    
  3. Set you normal PATH for your every day use in your shell's config file (.bashrc od .zshrc, etc)

  4. Connect to your FreeBSD box with VScode's remote SSH extension!

@morganwdavis
Copy link

morganwdavis commented Mar 13, 2025

@fsackur I'm running Version 1.98.2 (latest release as of now) using the steps described here in VS Code Server and Remote SSH on FreeBSD with remote.SSH.useExecServer enabled and no issues. Also, all extensions are up to date, notably Remote - SSH.

$ uname -a
FreeBSD dtl-08 14.2-RELEASE-p1 FreeBSD 14.2-RELEASE-p1 GENERIC amd64
$ pkg info | grep linux
linux-rl9-libsigsegv-2.13_1    Handling page faults in user mode (Rocky Linux 9.4)
linux_base-rl9-9.5_3           Base set of packages needed in Linux mode (Rocky Linux 9.5)

@ArjanKn
Copy link

ArjanKn commented Dec 28, 2025

@morganwdavis Thanks for the write-up 'vscode-server-freebsd'. I used it to access a remote FreeBSD-15 but run into 2 issues, one with the detection of the remote and one with vscode-1.107.1 (on windows).

To make it work, add RemoteCommand /compat/linux/usr/bin/bash to ssh config for FreeBSD, and because of this line a few knobs in the windows vscode settings.json file must be checked for the remote-ssh extension: [explicit in the settings.json file, since the setting it in the gui has an issue]:

  • "remote.SSH.useLocalServer": true
  • "remote.SSH.enableRemoteCommand": true which requires the "remote.SSH.useLocalServer": true and
  • "remote.SSH.remotePlatform": { "NB4029": "linux", "RHEL9": "linux", } does NOT list the remote for FreeBSD using the RemoteCommand

Once this was in place, the connection initializes selecting linux as the remote, however the terminal shell in vscode refers the native FreeBSD shell, but the shell used for various vscode extensions uses /compat/linux/usr/bin/bash shell chroot'ed to /compat/linux.
Vscode reports an issue with the useLocalServer probably because in the /compat/linux chroot there is no ssh available...

@morganwdavis
Copy link

@ArjanKn Thanks for the details to get this working on FreeBSD 15. I've yet to update my 14.3 dev server to 15 so I've not tried this yet. Can you confirm you're using the .bash_linux file and the custom ssh setting in rc.conf as described in my write-up?

@ArjanKn
Copy link

ArjanKn commented Dec 29, 2025

@morganwdavis Yes, snippets from the various files:
/etc/rc.conf: linux_enable="YES"
/etc/ssh/sshd_config: AcceptEnv BASH_ENV
~/.bash_linux:PATH="/compat/linux/usr/local/sbin:/compat/linux/usr/local/bin:/compat/linux/usr/sbin:/compat/linux/usr/bin:/compat/linux/sbin:/compat/linux/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

env: SHELL=/usr/local/bin/zsh // also used bash as shell for user arjan, but that resulted in problems with connecting.

.ssh/config:

Host FreeBSD15
    HostName 192.168.1.153
    User arjan
    SetEnv BASH_ENV="~/.bash_linux"
    RemoteCommand /compat/linux/usr/bin/bash

Installed remote extensions: 'github copilot chat' and 'microsoft c/c++ Extension Pack'

It works to some extend, 'open remote folder' in home directory and within the /compat/linux chroot. CMake extension seems to be bound to the same directories, not able to find the installed C/C++ compilers in FreeBSD....

@morganwdavis
Copy link

@ArjanKn I don't have a /etc/sshd/sshd_config on 14.3. Maybe that's new for 15. Do you have this in /etc/rc.conf?

sshd_enable="YES"
sshd_flags="-o AcceptEnv=BASH_ENV"      # Allow VS Code Remote SSH connections

@ArjanKn
Copy link

ArjanKn commented Dec 30, 2025

@morganwdavis
It's a typo should be /etc/ssh/sshd_config.
sshd_flags="-o AcceptEnv=BASH_ENV" is the same as the line in /etc/ssh/sshd_config: AcceptEnv BASH_ENV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment