This post is a collection of a few tips and tricks for developing openCV applications on a Raspberry Pi (or any other embedded linux board) over SSH. You will learn:

  • How to develop over an SSH connection in VS Code
  • How to forward windows from the pi to your PC

These tips can be applied to any embedded Linux board, but I target the pi here since it’s so generally accessable.

Editing Using VS Code Over SSH

Chances are you don’t want to do all of your projects over SSH using vim or emacs. Using the built-in text editors from Raspbian aren’t much friendlier either. Beyond recommending that you become at least minimally proficient in vim (since you still often need it to set things up), here is how I edit using VS code over an SSH connection.

  1. Prerequisites: have VS Code installed and be able to SSH into your pi from your desktop.

  2. Install the SSH FS extension for VS code.

    I didn’t need to fiddle with the configuration file, everything was configured automatically with the install and restart VS code procedure.

  3. Bring up the command palette from View > Command Palette or cmd/ctrl + shift + P.

    Start typing ssh and choose SSH FS: Create a SSH FS Configuration. Enter a name for the configuration.

  4. You will then get a tab with some configuration options. Let’s look at how mine is configured and then I’ll explain the options.

    // If you haven't already, associate .jsonc files with "JSON with Comments (jsonc)
        "label": "Raspberry pi",
        "root": "~",
        "host": "",
        "port": 22,
        "username": "your_password",
        "password": "raspberry"
    • label: just for your information
    • root: the directory on the pi that will show up in the VS Code sidebar as an open directory. You could use ~ or the path to some project directory on the pi.
    • host: the IP address of the pi. This is identical to the one you use when you SSH into it over a terminal.
    • port: the port that the SSH connection will occur on. You can leave it unless you’re doing something special.
    • username: username you’d use when SSHing into the pi (pi by default)
    • password: the password associated with the username above (raspberry by default)

    Save and close this file.

  5. Connect to the pi by expanding the SSH FILE SYSTEMS section of the sidebar, right clicking on the configuration you just added, and choosing connect.

X Window Forwarding

I like to run my pi headless, meaning I only ever SSH into it from my laptop and never directly connect a screen. This is just easier and lets me use my screens for my main workstation. Regular SSH is text-based so you won’t see any windows. This is no good when you’re messing with cameras and you want to see if your vision algorithms are working.

Forwarding X windows over an SSH connection is easy to set up, however. I find it particularly useful for openCV imshow windows.

  1. On the enable X window forwarding by editing the sshd config file. I use vim, so I enter:

    vi /еtс/ѕѕh/ѕѕhd_соnfіg

    Add the following line to the bottom of the file, save and close it:

    X11Forwarding yes
  2. Now you need to restart SSH. Do so with this command:

    sudo /еtс/іnіt.d/ѕѕh rеѕtаrt
  3. Connect back up to the pi with SSH as normal, except add the -X flag to enable X window forwarding. It is also possible to use -Y instead of -X.

    ssh -X pi@

    Note: use the correct IP address for your pi in this command.

  1. Now if you run any code that should open a window, the window will pop up on your computer’s desktop. Nice!