Remote Raspberry Pi Development Using Visual Studio Code

Remote Raspberry Pi Coding With Visual Studio Code

Remote Raspberry Pi Development Using Visual Studio Code

I don't have a spare monitor and didn't fancy connecting the Pi to my monitor every time I wanted to write some code. I also wanted to be able to code from anywhere, i.e. not have be connected via a cable.

Ideally I want to be able to develop on either of my laptops (PC and Mac) via wifi using Visual Studio Code.

Is this even possible?

A quick Google search brought up a few options, all of which started with setting up SSH, in particular password-less SSH.

Fortunately, this is very straightforward these days as Microsoft has been agressively embracing Linux features and tools within the Windows ecosystem. OpenSSH, for example, is now installed on Windows 10 by default.

Step 1: Setup password-less SSH to the Raspberry Pi

First, we need to generate SSH keys, so we run the following command on the laptop:

[Replace {USERNAME} with the username of the user on your PC]

ssh-keygen -t ed25519

When you run this command you will asked "Enter file in which to save the key" and it will show the default location of the current users directory. You can keep the default location and filename by just pressing return.

This will create a .ssh folder in C:\Users\{USERNAME} containing 2 files: id_ed25519 and

The is the public SSH key and now needs to be copied to the Raspberry Pi.

Step 2: Copy the public SSH key to the Raspberry Pi

The public key now needs to be copied to the .ssh directory on the Raspberry Pi. If this directory does not exist then using the terminal on the Pi enter this command:

mkdir ~/.ssh

Now, back on your Windows PC use the scp command (Secure Copy Protocol) to copy the public key from your PC to the .ssh directory on the Pi

[Again, replace {USERNAME} with the username of the user on your PC and {PI_ADDRESS} with the IP address of your Raspberry Pi]

scp C:\Users\{USERNAME}\.ssh\ pi@{PI_ADDRESS}:~\.ssh\authorized_keys

You will be prompted for the SSH password, which if you haven't changed it yet will be the default Pi password of raspberry

Step 3: Test SSH to the Raspberry Pi

To test that you can now SSH to your Pi without a password, at a command prompt on your PC start a SSH session:

ssh pi@{PI_ADDRESS}

The SSH connection should now start without prompting for a password.

Step 4: Install Visual Studio Code

Head over the Microsoft site to download and install VS Code:

Next, install the Remote Development Extension Pack

The Remote Development Extension enables you to use VS Code to develop on remote machines, in this case your Raspberry Pi.