Raspberry Pi Setup SSH to Connect Externally
Connect from anywhere!
What you need
So you want to connect to your Raspberry Pi from outside your local network? If you've gotten this far you've probably purchased a Raspberry Pi, set it up, and wished you could tinker with it from afar. If you haven't setup your Raspberry Pi yet a separate tutorial guides you through the setup process.
This tutorial assumes you've already setup local SSH, and have PuTTY installed on a windows computer.
Let's get started!
Step 1: Finding your external IP address
The first step to find your external IP address. This is pretty easy and there are many different tools and techniques. Here's two.
If you have access to a web browser connected to the same local network, on the Raspberry Pi or another computer, there are multiple websites you can visit that will show you your IP address.
- One site is http://www.whatsmyip.org/
- Or search google.com for "What's My IP Address"
If you're connected to the Raspberry Pi and in command line, either by physical keyboard and monitor or local SSH, you can type this into the command line and press enter to see your external IP address. No mater how you find it, write it down.
curl ipecho.net/plain ; echo
Step 2: Check if the SSH port is open, and forward the port if not.
The next step can get tricky. SSH connections usually travel through port 22. This means that an outside request will target your external IP address, request to go through port 22, get directed to your Raspberry Pi, and then successfully setup the SSH connection. Let's make sure all these steps will be successful.
First use a port checking tool to see if port 22 is open on your external IP address.
YouGetSignal is the port checker we'll be using.
Open up the port checker, enter your external IP address, and port number 22, and click check.
You should receive a notice that the port is closed. This most likely means you need to setup port forwarding on your router.
Port forwarding is a tricky subject. Every ISP and router are different so we can't write a short guide that will cover exactly how to do it on every setup. Instead here are the basic instructions.
Your goal is to forward external requests to port 22, to the local IP Address of the Raspberry Pi at port 22. Here's the general outline of how you do that.
- Log onto your local router by typing it's local IP address into a web browser
- This is typically http://192.168.1.1 or http://192.168.0.1
- Login to your router with the username and password that are printed on your router. If no username and password is printed on the router, find the make and model of your router, and search Google for "[make] [model] router default password"
- Find the list of networked devices, find your Raspberry Pi on the list, and write down the local IP address. It should be in the form of 192.168.x.x
- Find an option that says "Port Forwarding"
- Create a new port forwarding rule that targets the local IP address of your Raspberry Pi and port 22.
(Some Verizon Fios routers seem to work best when configured as TCY Any -> 22 instead of 22 -> 22. This setup may be less secure than desired, but is useful for getting started and verifying that everything works)
Step 3: Connect to your Raspberry Pi
Now that your port-forwarding rules are active. It's time to trying connecting to the Raspberry Pi.
To do this use another computer connected to the internet. Assuming you're on a Windows computer, open up PuTTY. If you're not already using PuTTY, it can be downloaded and installed from here.
On PuTTY's main screen, enter your external IP address, and port 22. The connection should go through, and you'll be asked for a username and password. Once you login you're now connected to the Raspberry Pi! Now even if you're on the same local network as the Raspberry Pi, if you connected to the external IP address, then you've connected from an "external" network. This means you can now connect to your Raspberry Pi from any internet connected device.
Why do you use SSH?
Connect with your cell phone
If you're connected to 3G or 4G service on your cell phone's data plan, you can control your Raspberry Pi from your cell phone.
For Android phones, the best SSH Client we've found is JuiceSSH and is available on the Google Play Store. JuiceSSH is a highly rated and fully featured SSH client for android.
For the iPhone and iPad, Server Auditor is a highly rated SSH client.
Using either of these apps will allow you to log-in and tinker with your Raspberry Pi from literally anywhere with a data connection.
Congratulations! You've moved forward another step in your Raspberry Pi journey!
Having trouble? Is something unclear? Excited about Raspberry Pi? Leave a comment below to join the conversation!