This blog post is an all-in-one setup guide for all of you interested in having both over the internet (remote) and LAN access to SSH terminal for your Raspberry Pi.
- ⛔ no port forwarding on your router
- ⛔ no static IP needed
- ⛔ no VPN server configuration
We start from installing the Raspberry Pi system image, then go through configuration of Wi-Fi connection, finishing on establishing VPN network between your laptop and Raspberry Pi.
If you already have your system installed, and Internet connected, you can drop this section and go to section about establishing VPN connection
Instruction is on this website: https://www.raspberrypi.org/software/. The easiest way is to use Raspberry Pi Imager.
A quick installation guide for Linux (tested on Ubuntu 20.04):
- Download Raspberry Pi Imager from this website: https://downloads.raspberrypi.org/imager/imager_1.5_amd64.deb
imager_1.5_amd64.debpackage that you just downloaded, by executing the following command in the Linux terminal:
- Run in the Linux terminal (I work on Ubuntu 20.04):
- Click [Choose OS] and select eg. "Raspberry Pi OS (32-bit)"
- Insert SD card to your laptop and choose by [Choose SD Card] button and click [Write] button
- Insert SD card with the system image into the Raspberry Pi, connect a display to HDMI, mouse and keyboard to USB ports and power your system
During the onboarding process you should be asked to choose a Wi-Fi network you would like to be connected to. You can save more Wi-Fi networks in the Raspberry Pi system by editing
Then to list available networks execute:
, and to select a network:
[TODO: setup autoconnect if one of the networks is temporary unavailable]
Sometimes it is good to have access to Raspberry Pi terminal not only over display/keyboard/mouse or LAN, but also over a serial interface. To do so edit
/boot/config.txt file, add line
enable_uart=1 and save. Connect your serial adapter to GPIO14 (TXD), GPIO15 (RXD) and GND (for Raspberry Pi 4) and run the following command in the terminal on your laptop:
(if your serial adapter is available under /dev/ttyUSB0).
To exit the screen and return to your bash, type ctrl+a, then k.
To make an over-the-internet connection between your laptop and Raspberry Pi we will setup a VPN network. We will install Husarnet VPN Client on your Raspberry Pi and laptop.
Husarnet Client creates a virtual network interface on the level of your operating system. So from your applications point of view it's like a network adapter with IPv6 (but works over physical IPv4 or IPv6 networks provided by Ethernet, Wi-Fi, LTE or 5G). Husarnet is trying to establish a direct, peer-to-peer connection between your devices, so latency is minimized and you do not need to worry about configuring a VPN server.
Husarnet infrastructure is used to help your devices find each other over the Internet, even if they do not have a static IP addresses, or are behing NAT's and firewalls.
Husarnet is free to use for up to 5 devices, without any transfer limits. We do not care about how much data your devices transfer because the traffic goes directly between them, not through our servers. We don't even know how much data you transfer :)
after the installation process is finished, run:
At first you will need to obtain a Husarnet join code for the network you want your devices to be connected to. To find your join code, create an account and log into https://app.husarnet.com . Then create a new network, by clicking [Create network] button, and then click [Add element] button. Your join code will be available under
join code tab:
It looks like this:
Now when you have your join code available all you have to do is to execute:
a) on your Raspberry Pi:
b) on your laptop:
mylaptop are easy to remember host names under which you will be able to access your devices.
At this point you are able to connect to your Raspberry Pi over the Internet or in LAN the same way.
For example you can ping your Pi (remember to use
ping6 instead of
ping because Husarnet creates a virtual LAN network based on IPv6):
You can also just SSH your pi from your laptop.
By default SSH is disabled in Raspberry Pi. You can enable it by executing the following command in the RPi's terminal:
Then go to
3 Interface Options >
P2 SSH > "Would you like the SSH server to be enabled?" select
<Yes>. Now exit raspi-config.
Now you can SSH to your Pi just by using it's host name:
I hope this simple guide about accessing Raspberry Pi over the Internet (by using SSH) will prove useful.
In this article you learned:
- how to access Raspberry Pi command line with low latency over the Internet even if your device is behind NAT or firewall
- how to use your Raspberry Pi hostname instead of IP address
I showed you how to access your Raspberry Pi over the Internet under 5 minutes using Husarnet VPN, and without the need to worry about:
- static IP
- port forwarding on your routers
- dynamic DNS
- configuring VPN servers (because Husarnet is a peer-to-peer VPN)