Simple Raspberry Pi Lite setup with SSH and VS Code from Linux Mint
As you progress in programming and technology in general at some point you’ll most likely feel comfortable ditching the GUI for an OS. This is intended to a super quick walkthrough for how to setup ssh to another Linux machine. While this tutorial uses a Raspberry Pi on a home network, the process is the same for any Linux Machine that has ssh enabled and you have sufficient access to add public keys to. So lets jump right in.
Raspberry Pi Setup:
It’s never been easier to setup a Raspberry Pi with the introduction of Pi Imager. Just head over to https://www.raspberrypi.com/software/ and download the Pi Imager.
Once the .deb package is downloaded
you can simply click on the package and then click the Install Package button
or if you want to be cool just navigate to your downloads and run:
dpkg -i <imager deb name>.deb
However you may run into an issue with dependencies missing. Doh!
To fix this issue simply run
sudo apt-get -f install
Now that Imager is installed click on the home button and type “Imager.” You should be able to simple click on the icon and start the program.
Once it is open click on CHOOSE OS and browse to the image that you would like to load. Note: If you are using a Pi 3 or earlier you will most likely need to select a 32 bit OS. I’m using a Raspberry Pi 4 so will use a 64 bit OS.
Here I’ll select other and choose a Lite version because I will not need a GUI and will only be using SSH.
Now select CHOOSE STORAGE
You should have a Micro SD plugged into your PC for the Raspberry PI OS. In my case I have a 32 GB SD card in a USB adapter plugged in.
Now this is the really cool part about Pi Imager. All the configurations which used to be a chore when setting up a Raspberry Pi can now be set when writing the image!
You can set the host name, enable SSH and automatically have the public key placed on the Pi.
Check the box for Configure wireless LAN and enter your Wifi password to connect it to your Wifi
Set the country and locale
Click SAVE and then click WRITE. This will take a few minutes. Once it has finished pop the SD card out, put it in your Pi and fire it up.
Connecting to the Pi:
Uh oh. We don’t have a way to login. How do we find the IP of the Raspberry Pi. Fear not. You have two options.
- If you have access to your DHCP Server (your modem router) you can login and track down what IP was assigned to it.
- If you have nmap you can scan your home networks IP range
Logging into my modem/router.
Never mind about the odd IP address. I made my subnet kind of funky. Yours will most likely be 192.168.1.X or 10.12.0.X or something like that.
nmap -sP <your starting subnet number>/24
nmap -sP 192.168.1.0/24
This report will give you the IPs and it will be a lot of trial and error to find the Pi
You can test it though by running:
ssh pi@<the ip address>
If you’ve connected to this IP address before with SSH you may get a warning that you need to run a command to remove the ECDSA host key. Just run the command it gives you and then reconnect.
Lets make connecting easier:
In your modem/router you will want to make an IP reservation for the Pi so that it retains the same IP (I’ll let you google how to do that. It’s most likely just a button click)
On your local machine add an entry to your hosts file
sudo nano /etc/hosts
Here I just add an entry for the Raspberry Pi’s IP and the name I want to refer to it as.
Now I can connect just running
But it get’s easier
I am VERY lazy. Like holding shift and pressing the number 2 to type the @ sign. Exhausting. Lets make it so we can just type ssh and a name.
Create a file called config in your .ssh directory if you don’t already have one. If you do already just add a new entry in it. The format is:
Host <Whatever short name you want>
HostName <The IP of your PI>
Now I can simply connect by typing:
Install Visual Studio Code and connect to your Pi:
Head over to https://code.visualstudio.com/download and select the version appropriate for your OS. I’m using Linux Mint so will choose the .deb.
Follow the same process we used for Pi Imager.
Once it has installed open Visual Studio Code and go to Extensions and search for SSH. We are looking for Remote - SSH from Microsoft.
Once installed you should see a green icon in the lower left corner of your screen.
Once you click the green section you should see the drop down at the top open up. Select “connect to Host”
You will then be presented with all of the entries from your .ssh/config file.
Once connected you can navigate the file system through Visual Studio code as well as press Ctrl +`. That is the back-quote or backtick or actually whatever you want to call it. It’s the darn key next to the number one on your keyboard.
I hope this article helps folks out there that want to get up and running quickly with their Raspberry Pi or helps streamline connecting for those who already have one running.
If you already have a Raspberry Pi setup for ssh and you’re using a password to authenticate just ssh to your Pi. Then on your local machine cat out your public key with
Copy the contents and paste them to a file on your Pi at .ssh/authorized_keys. That’s it, you should be good to go with SSHing without using a password.