How to Set Up Visual Studio Code for Remote Development on Raspberry Pi via SSH
1. Install VSCode and Remote Development Extensions
- Ensure you have Visual Studio Code installed on your local machine. If not, you can download it from here.
- Install the Remote - SSH extension in VSCode. You can do this by:
- Opening VSCode.
- Clicking on the Extensions view icon on the sidebar.
- Searching for Remote - SSH and installing it.
2. Enable SSH on Your Raspberry Pi
- SSH should be enabled on your Raspberry Pi by default. If it’s not, enable SSH using the following steps:
- Open a terminal on your Raspberry Pi.
- Run the command on Paspberry Pi:
sudo raspi-config
- Navigate to Interfacing Options > SSH > Enable.
3. Find Your Raspberry Pi’s IP Address
- On your Raspberry Pi, run the following command on Paspberry Pi to get the IP address:
hostname -I
- Take note of the IP address shown (e.g.,
192.168.x.x
).
4. Configure SSH on Your Local Machine
- If you haven’t already, generate an SSH key pair on your local machine (if you don’t have one):
- Open a terminal/command prompt on your local machine(PC).
- Run on Local Machine(PC) :
ssh-keygen
- terminal:
Enter file in which to save the key:
Enter(default)Enter passphrase (empty for no passphrase):
EnterEnter same passphrase again:
Enter
- Follow the prompts to generate the key. The default location for storing the key is fine
- Linux: usually
~/.ssh/id_rsa
- Windows: usually
C:\Users\<username>\.ssh\ir_rsa
- Linux: usually
- (Linux): Copy your SSH public key to the Raspberry Pi.
- Run:
ssh-copy-id pi@<raspberry_pi_ip>
- Replace
<raspberry_pi_ip>
with the IP address of your Raspberry Pi. - Enter the password when prompted.
- Run:
- (Windows): There is no command to copy the public key directly.
- Open the public key and copy it on PC terminal
- Run:
type C:\Users\<Username>\.ssh\id_rsa.pub
- Access Raspberry Pi’s SSH :
ssh pi@<raspberry_pi_ip>
- Create
.ssh
Folder on Raspberry Pi and paste the public key
1
2
mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys
- Test SSH Access:
- Able to SSH into your Raspberry Pi from your Windows machine without a password: `ssh pi@
- Able to SSH into your Raspberry Pi from your Windows machine without a password: `ssh pi@
5. Configure VSCode to Connect via SSH
- Open VSCode.
- Press
Ctrl + Shift + P
to open the Command Palette. - Type and select Remote-SSH: Connect to Host….
- Enter the following:
pi@<raspberry_pi_ip>
- Replace
<raspberry_pi_ip>
with the IP address of your Raspberry Pi.
Optional: Save Connection
- You can save this SSH connection for easier access in the future:
- Go to File > Preferences > Settings.
- Search for Remote.SSH: Config File.
- Edit the (Linux):
~/.ssh/config
or (Windows):C:\Users\<username>\.ssh\config
file to add config:
1
2
3
4
5
# For Linux
Host raspberrypi
HostName <raspberry_pi_ip>
User pi
IdentityFile ~/.ssh/id_rsa`
1
2
3
4
5
# For Windows
Host raspberrypi
HostName <raspberry_pi_ip>
User pi
IdentityFile C:\Users\<username>\.ssh\config
- This way, you can simply type
raspberrypi
in the Remote-SSH: Connect to Host command.
6. Start Editing on Raspberry Pi
This post is licensed under CC BY 4.0 by the author.