Skip to content

Raspberry Pi SSH: Remote access from any network | ShillehTek

May 02, 2024

Video Tutorial

Watch first if you want to see the full process of enabling SSH and connecting to your Raspberry Pi from an external network.

Project Overview

In this tutorial, you will set up a Raspberry Pi to accept SSH connections from an external network, so you can remotely control and manage your Pi from anywhere in the world.

This builds on a local-network SSH setup by removing the local-only limitation using a static IP on your LAN and router port forwarding.

If you want to support the creator or hire help for IoT work, these original links are included:

  • Time: 20 to 45 minutes (depends on your router UI)
  • Skill level: Beginner to Intermediate
  • What you will build: A Raspberry Pi that you can SSH into from outside your home network

Parts List

From ShillehTek

  • None required for this software and network setup.

External

  • Raspberry Pi with Raspbian OS installed
  • Access to your home router (admin panel)
  • Internet connection
  • Basic familiarity with the command line

Note: Port forwarding menus and names vary by router model. The static IP you choose must be on the same subnet as your router for proper network communication.

Step-by-Step Guide

Step 1 - Enable SSH on your Raspberry Pi

Goal: Make sure the SSH service is enabled so the Pi can accept remote connections.

What to do: Connect your Raspberry Pi to a monitor and keyboard, then open the terminal from the desktop.

Run the following command:

sudo raspi-config

Navigate to Interfacing Options, then SSH, and select Enable. Exit the configuration tool.

Expected result: SSH is enabled on the Raspberry Pi.

Step 2 - Set up a static IP address on your local network

Goal: Give your Raspberry Pi a consistent LAN IP address so port forwarding always points to the correct device.

What to do: Open a terminal on your Raspberry Pi and edit the DHCP client configuration file:

sudo nano /etc/dhcpcd.conf

Scroll to the end of the file and add your static IP configuration (example shown below). Make sure the IP is on the same subnet as your router.

# Example static IP configuration:
interface wlan0
static ip_address=192.168.1.100/24
# Ensure this IP is on the same subnet as your router's IP
static routers=192.168.1.254
static domain_name_servers=192.168.1.254 8.8.8.8
  • Replace wlan0 with eth0 if you are using an Ethernet connection.
  • The IP address 192.168.1.100 should be in the same IP range as your router (for example, if your router is 192.168.1.254, then 192.168.1.XXX is appropriate).
  • Save and exit by pressing CTRL+X, then Y, and Enter to confirm.

Reboot your Raspberry Pi to apply the changes:

sudo reboot

Expected result: Your Raspberry Pi comes back up on the same local IP address you configured.

Step 3 - Configure port forwarding on your router

Goal: Allow inbound connections from the internet to reach your Raspberry Pi SSH service.

What to do: Log into your router admin panel by entering its IP address in a browser. Find the Port Forwarding section.

Add a new rule to forward an external port (for example 2222) to your Raspberry Pi internal IP address (for example 192.168.1.100) on port 22 (SSH). Save your settings.

If anything is unclear, refer to the YouTube video above because the exact screens vary from router to router.

Expected result: Your router forwards inbound traffic on the chosen external port to the Raspberry Pi on port 22.

Step 4 - Connect remotely using SSH

Goal: SSH into your Raspberry Pi from a device outside your local network.

What to do: From any SSH-capable device, open your SSH client and connect using your external IP and the forwarded port:

ssh pi@your-external-ip -p 2222
  • Replace your-external-ip with your actual external IP address.
  • Enter your Raspberry Pi credentials when prompted.
  • Replace pi with your Raspberry Pi username sign-in.

Expected result: You get a remote terminal session on your Raspberry Pi over SSH.

Step 5 - Apply basic SSH security tips

Goal: Improve security for an internet-exposed SSH setup.

What to do:

  • Change the default password of the pi user to enhance security.
  • Consider setting up key-based authentication for SSH.
  • Regularly update your Raspberry Pi to keep it secure.

Expected result: Your SSH access is more secure for ongoing remote management.

Conclusion

You now have a Raspberry Pi configured with SSH, a static local IP, and router port forwarding so you can connect remotely from an external network. This approach is useful for IoT projects where you need to control and manage devices from anywhere.

Want parts and tools for your next Raspberry Pi or IoT build? Shop at ShillehTek.com. If you want help designing or deploying a secure remote-access IoT setup, check out our consulting at https://shillehtek.com/pages/iot-consulting.