Remote Access Your Raspberry Pi From Anywhere With SSH Tunneling

Learn how to connect your Raspberry Pi to the internet and access it remotely, even when you’re not at home. …


Updated August 27, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to connect your Raspberry Pi to the internet and access it remotely, even when you’re not at home.

Raspberry Pi is a versatile and affordable computer that can be used for various purposes ranging from media centers to robotics projects. One of the most powerful features of Raspberry Pi is its ability to connect to the internet, which allows users to control their devices remotely, even when they’re not physically present. This guide will show you how to set up remote access to your Raspberry Pi using SSH (Secure Shell) tunneling and a VPN service like ExpressVPN.

Step 1: Enable SSH on Your Raspberry Pi

Before you can connect remotely, you need to enable the SSH (Secure Shell) service on your Raspberry Pi. SSH allows you to access your device’s terminal over a network connection, which is essential for remote access. Follow these steps to enable SSH:

  1. Open the terminal on your Raspberry Pi by going to Menu > Accessories > Terminal.
  2. Type sudo raspi-config and press Enter.
  3. Navigate to Interfacing Options > SSH and select “Enable”.
  4. Choose Finish, then Reboot when prompted.

Now that SSH is enabled, you can access your Raspberry Pi’s terminal remotely using an SSH client like PuTTY on Windows or Terminal on macOS/Linux.

Step 2: Set Up a Static IP Address

To make connecting to your Raspberry Pi easier, assign it a static IP address so you can always access it using the same address. This is particularly useful if your router assigns dynamic IP addresses based on DHCP (Dynamic Host Configuration Protocol). Follow these steps to set up a static IP address:

  1. Open the terminal and type sudo nano /etc/dhcpcd.conf to edit the dhcpcd configuration file.
  2. Scroll down to the bottom of the file and add the following lines, replacing “your_ip” with an unused IP address on your network (e.g., 192.168.1.100) and “your_subnet” with your subnet mask (e.g., 255.255.255.0):
interface eth0
static ip_address=your_ip/your_subnet
static routers=192.168.1.1
static domain_name_servers=8.8.8.8.8 8.8.4.4
  1. Press Ctrl+X, then Y, and Enter to save your changes.
  2. Reboot your Raspberry Pi by typing sudo reboot.

Now your Raspberry Pi will always have the same IP address on your network. Note that you may need to adjust the IP address and subnet mask based on your specific network configuration.

Step 3: Set Up Port Forwarding on Your Router

In order for remote connections to reach your Raspberry Pi, you’ll need to forward a port on your router to its static IP address. Follow these steps to set up port forwarding:

  1. Log in to your router’s admin interface by entering its IP address (e.g., 192.168.1.1) in a web browser.
  2. Navigate to the Port Forwarding or Virtual Server settings page.
  3. Add a new port forwarding rule with the following details:
    • Protocol: TCP
    • External Start Port: 22 (the default SSH port)
    • Internal Start Port: 22
    • IP Address: The static IP address you assigned to your Raspberry Pi in Step 2
  4. Save and apply the changes.

Step 4: Connect Your Raspberry Pi to a VPN Service

To ensure your remote connection is secure, connect your Raspberry Pi to a VPN service like ExpressVPN. Follow these steps to set up ExpressVPN on your Raspberry Pi:

  1. Sign up for an ExpressVPN account and download the Linux client from their website (https://www.expressvpn.com/support/vpn-setup/raspberry-pi-router/).
  2. Extract the downloaded file using tar -xzf expressvpn-raspbian.tar.gz.
  3. Run ./install.sh to install the VPN client.
  4. Open the ExpressVPN app by going to Menu > Programming > ExpressVPN and log in with your account details.
  5. Choose a server location and connect.

Now, all your internet traffic from your Raspberry Pi will be routed through the VPN, providing an extra layer of security for remote connections.

Step 5: Connect Remotely Using SSH Tunneling

With your Raspberry Pi configured for remote access, you can connect to it from anywhere using an SSH client and a VPN-enabled connection. Follow these steps to set up SSH tunneling with PuTTY on Windows or Terminal on macOS/Linux:

  1. Install an SSH client like PuTTY (Windows) or Terminal (macOS/Linux).
  2. Open the SSH client and enter your router’s public IP address in the Host Name (or IP address) field.
  3. Set the Port to 22 and click Connect (or type ssh pi@your_router_ip in Terminal).
  4. Enter the username and password for your Raspberry Pi (default is “pi” with password “raspberry”).
  5. Once connected, you can run commands on your Raspberry Pi as if you were sitting at your desk.

Now you have a secure remote connection to your Raspberry Pi over the internet. Enjoy controlling your device from anywhere with an internet connection!