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!

@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