Access your Raspberry Pi from anywhere with just a few clicks and some setup time!
Learn how to set up remote access to your Raspberry Pi so you can control it and view its output from any device with an internet connection. This guide will show you how to use a popular tool called …
Updated October 1, 2023
Learn how to set up remote access to your Raspberry Pi so you can control it and view its output from any device with an internet connection. This guide will show you how to use a popular tool called ngrok to create a secure tunnel to your Pi.
Remote accessing your Raspberry Pi allows you to control it and view its output from anywhere in the world with just a few clicks. With the help of a simple tool called ngrok, you can easily set up a secure tunnel between your Pi and your device. This guide will show you how to do it step-by-step.
Before we begin, make sure you have the following:
- A Raspberry Pi with an internet connection (preferably running Raspbian OS)
- An account on ngrok.com (you can sign up for a free plan)
- SSH access to your Raspberry Pi enabled (if not, follow this guide to set it up: https://www.raspberrypi.org/documentation/remote-access/ssh/)
Step 1: Install ngrok on your Raspberry Pi
To install ngrok on your Pi, run the following command in the terminal:
curl -sSL https://ngrok.io/install.sh | sudo bash
This will download and install ngrok on your Pi.
Step 2: Set up an authtoken for ngrok
Create a free account on ngrok.com to get an authtoken. Once you have signed up, copy the token provided in the dashboard. Then run the following command on your Raspberry Pi:
ngrok authtoken <your_token>
Replace <your_token>
with the token you just copied from ngrok.com.
Step 3: Run ngrok to create a secure tunnel
Now that ngrok is installed and authenticated, we can use it to create a secure tunnel between your Pi and your device. In the terminal on your Raspberry Pi, run:
ngrok tcp 22
This will create a tunnel from port 22 (the default SSH port) of your Pi to a random ngrok URL. The output will look something like this:
Session Status online
Account Your Name (Plan: Free)
Version 2.3.40
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding tcp://3.tcp.ngrok.io:15698 -> localhost:22
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Note the Forwarding
line - this is the URL you need to use to SSH into your Pi from anywhere.
Step 4: Connect to your Raspberry Pi remotely
Now that we have created a tunnel, we can connect to our Pi from any device with an internet connection. Use an SSH client (such as PuTTY on Windows or Terminal on macOS/Linux) and enter the ngrok URL in the format username@<ngrok_url>
, replacing <ngrok_url>
with the forwarding address from step 3:
ssh pi@3.tcp.ngrok.io -p 15698
Enter your Raspberry Pi’s password when prompted, and you are now remotely accessing your Pi!
Conclusion
With just a few steps and some setup time, you can now remote into your Raspberry Pi from anywhere in the world. ngrok creates a secure tunnel between your device and the Pi, allowing you to access it without having to worry about port forwarding or opening up unnecessary ports on your router. This makes it a great solution for working with headless Pis or accessing your Pi when away from home.