The raspberry pi is a single board computer (SBC) and is capable of running a desktop capable operating system so that we can code directly on it. But for me, a raspberry pi will likely to be used as a gateway or home automation agent. So it will probably be tucked away somewhere and accessed through using SSH.
The raspberry pi by default will not have the SSH server enabled so the first thing we will do is enable that. It is as easy as checking a checkbox.
By default the hostname is raspberrypi and the user is pi
Now let’s head over another machine and check that we can connect to it. Usually the first thing I do is quickly ping it just to make sure it’s there by executing the command “ping raspberrypi.local” where raspberrypi is the host name and local is the top level domain, in this case our local network.
Next let’s check that we can ssh into our raspberry pi.
We could perform a couple of extra steps so that we can ssh into our raspberry pi without needing to enter our password every time. We do this by copying the public ssh key of the machine we will be connecting from to the raspberry pi (assuming we already generated a private/public ssh key pair). This basically tell the raspberry pi to use this public key (lock) for authentication and the machine we are connecting from will have the private key (key) to complete the authentication process.
On the machine where we will be connecting from, add the following text to a file call “config” and save it under the “.ssh” folder. All we are saying here is when ssh into this host, use this key.
Host raspberrypi.local User pi IdentityFile ~/.ssh/id_rsa
That’s it. Now if we try to ssh into our raspberry pi again, you will see we won’t need to provide a password.
Remote development with VS Code:
Making a ssh connection with a remote machine is quite straight forward using the above extension. If you need more info, check out it’s documentation at VS Code marketplace.
Once we are connected, we can start coding just like our local machine.