Accessing Raspberry Pi SSH and VNC From Outside of the Local Network
This article goes over the best methods to access Raspberry Pi or any embedded Linux-based device terminal and desktop remotely.
Join the DZone community and get the full member experience.Join For Free
Raspberry Pi Single Board Computers are becoming more popular among both hobbyists and industrial IoT device vendors. Since its first announcement on February 29th, 2012, Raspberry Pi has made its way into hobby gaming consoles, industrial automation plants, smart avionics, and more.
Talking about IoT (both hobby and industrial/commercial level), the reason for integrating such a powerful microprocessor-based computer into a project or a product is the sheer processing power and expandability it brings to the table. What better way is there to let your Pi ‘talk to the world’ than to let it have a good, fast internet connection? Therefore, in this post, we will be discussing the options you have at hand on how to SSH into your Raspberry Pi from outside of your local network such as WiFi or LAN.
What’s SSH on Raspberry Pi?
*nix (Linux-based and Unix-based operating systems) have a fundamental feature to grant you access to your Linux server without having to physically visit the server or computer through the network. SSH stands for Secure Shell and is a secure communication protocol for executing commands remotely on a *nix based computer (i.e. system update commands, shutdown/reboot commands, etc.).
Why Would I Need to Access my Raspberry Pi Terminal and Desktop From the Internet?
There may be some situations in which you would like to connect to your Raspberry Pi (or any other Linux machine, for that matter) in order to do maintenance routing, such as updating or configuration, through SSH. From a local network perspective, this is as easy as typing
ssh <username>@<ip address of Raspberry Pi> in a client such as Putty (i.e.
However, when it comes to accessing your Raspberry Pi device outside of your network, this becomes a hassle since the device might not have a public IP address. Therefore, there are multiple methods that solve the case and help us access the Raspberry Pi terminal and desktop outside of the local network.
3 Methods to Access a Raspberry Pi Remotely
1. Router Port Forwarding
If your router allows port forwarding, you may expose the port 22 (default port for SSH connections) to the internet and using your network’s IP address, create an SSH connection with the Raspberry Pi. Note that if your IP is dynamic (which most of the networks today are), you’ll not be able to connect when the IP of your network changes.
2. Using a Remote Desktop Tool to Remotely Log Into Your Raspberry Pi and Open a Terminal
There are tools such as Teamviewer and Anydesk that can be installed onto Raspberry Pis that provide remote desktop access to your Raspberry Pi desktop. You may connect to your Raspberry Pi through such a method and open a terminal window on your Pi and execute shell commands there. (Note that this method only applies to Raspberry Pis that have a desktop environment running, and is not possible with ‘lite’ versions of Raspberry OS.)
3. Going With a Ready-to-Use Plug-and-Play Solution
Upswift.io provides a ready-to-use free platform to remotely access the terminal or the screen of Raspberry Pi, or any Linux-based device – Beaglebone, Nvidia Jetson Nano, etc. After registration to the platform, and connecting the Raspberry Pi, you will have the option to access it remotely, without any need to open router ports, or being in the same network.
Opinions expressed by DZone contributors are their own.