Raspberry Pi and VS Code Remote Explorer (via SSH)

Evan Frawley
Jan 24, 2022
8m read
views

TLDR: I bought a Raspberry Pi, SSH into it, and write code and various scripts. I use the VS Code Remote Explorer to open up the files on the Pi as if they were on my machine! I provide a quick guide on how to set it up!

I bought a Raspberry pi over the 2022 holidays. My inspiration for doing so was a mix between wanting to have a small computer to run periodic automations, wanting a fun project that I can hack on with whimsy, and removing the irritation for paying $5/mo for cloud compute for what would essentially be the same thing as a Pi.

Fortunately, I was able to get one of the Raspberry Pi 4 8GB kits! Even though it came with a 128GB SD card, I had a 256GB card lying around that I used instead of the one from the kit.

Setup was actually rather easy — if you set up as well, I'd recommend using an ethernet cable since downloading the OS over Wifi is pretty slow.

So here's a simple guide for setting it up:

  1. Before you begin, I assume you've already setup your Raspberry Pi and have connected it to a monitor / keyboard / mouse as per the setup instructions that came with your Pi. You'll need to have it connected to a monitor for the next step.
  1. Enable your Raspberry Pi to receive SSH connection over your local network. I used this quick guide. This is a pretty straightforward guide on how to enable your Raspberry Pi to be accessible via SSH within your local network. If you want to make your PI accessible outside your local network, you'll need to do some additional steps. You'll also want to write down the local IP address, which you can find using this guide.
  1. Via your command line, SSH into your Pi. should be something like ssh pi@192.168.1.X where X is likely to be different based on your local network. It also probably depends on your router as well. You can learn more about that here. You want to make sure that you can access your Pi from the device you want to use VS Code Remote Explorer.
  1. [Optional] After you connect via command line first, you can add your machine's public ssh key to the authorized_keys file so you don't need to put in your password each time! This guide should explain how to do it easily. This is nice to do because otherwise VS Code would prompt you to put in the password each time it wants to connect via SSH. This is great if you want to SSH into your Pi from multiple computers (I use both my personal Mac and gaming PC to SSH in, depending on what I'm feeling).
  1. Add VS Code Remote Explorer Plugin

searching for the plugin

preview of the plugin

  1. Add your Pi! You can either do this by editing your ~/.ssh/config file to add it as a host, or manually adding the Pi as a host via the UI in VS Code.

ssh targets dropdown

Select SSH Targets

config screenshot with host info

Add the SSH Host info to your SSH config

plus button to add host

Or you can manually add it with the "+" button under the SSH Targets dropdown
  1. Connect to your host and you're done!

open the folder

Click on the open folder button and then select the location you'd like to open up the file viewer

preview of working code

And now you can have an entire workspace accessible to you at any time on your local network!
  1. [Optional] Generate an ssh key on the Pi and add it to your Github, so you can read and write to your repos from your Pi.

Happy hacking! Perhaps in a future article I'll write about what I'm using my Pi for. Let me know if there's anything interesting I should do 😄

Made with ❤️ and ☕️