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

Implementing Google reCAPTCHA in a Simple React and Node.js App

Implementing Google reCAPTCHA in a Simple React and Node.js App

Learn how to protect your React applications from bots and spam with Google reCAPTCHA integration! This step-by-step tutorial...

AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

In this tutorial, I will guide you through the process of running Selenium with ChromeDriver inside an AWS...

How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

Learn how to use the MLX90614 with the Raspberry Pi Pico W and get infrared values in MicroPython.

Raspberry Pi Pico/Pico W Free Simulator

Raspberry Pi Pico/Pico W Free Simulator

Discover how to simulate Raspberry Pi Pico projects using Wokwi, a free online simulator for Arduino and MicroPython....

Interfacing the MPU6050 with Raspberry Pi Pico W in C++

Interfacing the MPU6050 with Raspberry Pi Pico W in C++

Interface with the MPU6050 using the Raspberry Pi Pico W in C++.

How to Write your First C++ Program on the Raspberry Pi Pico W

How to Write your First C++ Program on the Raspberry Pi Pico W

Write your first C++ Program on the Pico W in a few simple steps.

How to Use ThingSpeak with the Raspberry Pi Pico W

How to Use ThingSpeak with the Raspberry Pi Pico W

Learn how to create a real-time environmental monitoring system with the Raspberry Pi Pico W and ThingSpeak!

How to Use ADS1115 with the Raspberry Pi (Part 1)

How to Use ADS1115 with the Raspberry Pi (Part 1)

Discover how to expand your Raspberry Pi projects by integrating the ADS1115 ADC for precise analog signal reading....

How to Install Pip Packages in AWS Lambda Using Docker and ECR

How to Install Pip Packages in AWS Lambda Using Docker and ECR

Learn how to streamline AWS Lambda deployments by using Docker and Amazon Elastic Container Registry (ECR) to package...

Create Tabular Product Descriptions on Your Shopify Store

Create Tabular Product Descriptions on Your Shopify Store

Enhance your Shopify store's product pages with our comprehensive guide on implementing tabular descriptions. Learn how to add a...

Back to blog

Leave a comment

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