Remotely Control Raspberry Pi via SSH from External Network

Learn how to SSH into your Raspberry Pi from any network. This is critical in IoT since you can control your device from anywhere in the world with this technique. This is an extension of the previous video where we only showed how to set up SSH on the local network. We take it a step further in this tutorial by removing that limitation.
Before reading the remainder, be sure to subscribe and support the channel if you have not!
Subscribe:
Support:
Hire me at UpWork to build your IoT projects:
What You'll Need
  • A Raspberry Pi with Raspbian OS installed
  • Access to your home router
  • An internet connection
  • Basic familiarity with the command line

Step 1: Enable SSH on Your Raspberry Pi

Before you can remotely access your Raspberry Pi, you need to ensure SSH is enabled:
  • Connect your Raspberry Pi to a monitor and a keyboard.
  • Open the terminal from the desktop.
  • Enter sudo raspi-config in the terminal.
  • Navigate to 'Interfacing Options', then 'SSH', and select 'Enable'.
  • Exit the configuration tool.

Step 2: Setting Up a Static IP Address

A static IP address ensures that your Raspberry Pi is always accessible at the same address on your local network, which is crucial for reliable remote access. It's important to choose an IP address that is on the same subnet as your router to ensure proper network communication.
Open a terminal on your Raspberry Pi and edit the DHCP client configuration file by typing:
sudo nano /etc/dhcpcd.conf
Scroll to the end of the file and add your static IP configuration:
# 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
This adjustment emphasizes the need to ensure the IP address is on the same subnet as the router, which is crucial for the proper operation of the network.

Step 3: Configure Port Forwarding on Your Router

To access your Raspberry Pi from outside your local network, you'll need to set up port forwarding:
  • Access your router’s admin panel by entering its IP address in a browser.
  • Locate the ‘Port Forwarding’ section.
  • Add a new rule to forward an external port (e.g., 2222) to the internal IP address of your Raspberry Pi (192.168.1.100) on port 22 (SSH).
  • Save your settings.
If any confusion, see YouTube video above for more details on this, as it can vary from router to router.

Step 4: Connecting Remotely

Now that everything is set up, you can connect to your Raspberry Pi from anywhere:
  • From any SSH-capable device, open your SSH client.
  • Connect using your external IP and the port you forwarded:
ssh pi@your-external-ip -p 2222
  • Replace your-external-ip with your actual external IP address.
  • Enter your Raspberry Pi's credentials when prompted.
  • Also replace pi with your Raspberry Pi username sign-in.
Security Tips
  • 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.

Conclusion

Setting up your Raspberry Pi with a static IP and enabling remote SSH access is a great way to maximize its utility and securely manage it from anywhere. Whether you’re using it for personal projects or as a part of your smart home setup, these steps will ensure a reliable and secure connection. Please subscribe to the channel if you want to learn more about IoT, Raspberry Pi, and more! Feel free to ask questions.

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

How to Connect and Use the HCSR501 PIR Sensor with a Raspberry Pi Pico/Pico W

Learn how to set up the HCSR501 PIR sensor with a Raspberry Pi Pico to detect motion and trigger...

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Powering the Raspberry Pi Pico W with the MB102 Power Supply

Learn how to power your Raspberry Pi Pico W projects easily and flexibly with the MB102 Power Supply Module...

How to Use L298N Motor Driver with Pico W

How to Use L298N Motor Driver with Pico W

Learn how to use the L298N motor driver to control DC motors with the Raspberry Pi Pico W in MicroPython.

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Controlling an LED with a Snap Using the KY-037 Sound Sensor and Raspberry Pi

Discover how to set up, code, and activate the LED based on detected sound with the Raspberry Pi...

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

Getting Started with the KY-037 Sound Sensor and Raspberry Pi: Detecting Sound Using Python

In this tutorial, I’ll guide you through setting up the KY-037 sound sensor with a Raspberry Pi using...

How to Post to Reddit Using Python

How to Post to Reddit Using Python

Post to reddit automatically using a Python script.

How to Create a Time-Lapse Video with a Raspberry Pi Camera

How to Create a Time-Lapse Video with a Raspberry Pi Camera

Learn how to make a timelapse with your Raspberry Pi in Python.

How to Integrate the MPU6050 with the STM32 Blue Pill

How to Integrate the MPU6050 with the STM32 Blue Pill

Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.