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

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...

SSH Into Raspberry Pi with Tailscale VPN

SSH Into Raspberry Pi with Tailscale VPN

Effortlessly access and manage your Raspberry Pi from anywhere using Tailscale's secure mesh VPN.

Send Email with Lua and the ESP32

Send Email with Lua and the ESP32

In this tutorial, we delve into sending emails with the ESP32-S3 using Lua, focusing on the Xedge IDE's built-in SMTP...

How to Code with Lua on ESP32 with XEdge32

How to Code with Lua on ESP32 with XEdge32

Learn how to set up Xedge32 and start coding on the ESP32-S3 with Lua programming!

Stream Audio From Raspberry Pi to Local Computer

Stream Audio From Raspberry Pi to Local Computer

Discover the simplicity of streaming live audio directly from a USB microphone connected to your Raspberry Pi to...

SSH Raspberry Pi via Cell Phone

SSH Raspberry Pi via Cell Phone

This beginner-friendly guide will walk you through remotely controlling your Raspberry Pi using SSH through your cell phone.

Remotely Control Raspberry Pi via SSH from External Network

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...

Stream Video from Raspberry Pi Camera to YouTube Live

Stream Video from Raspberry Pi Camera to YouTube Live

Learn how to stream to YouTube from a Raspberry Pi Camera.

How to Connect BH1750 with Arduino: Measure Ambient Light

How to Connect BH1750 with Arduino: Measure Ambient Light

Learn how to measure ambient light for smart lighting control using Arduino and the BH1750 Light Intensity Module.

How to Connect MPU9250 and Raspberry Pi (Part 2 - Calibration)

How to Connect MPU9250 and Raspberry Pi (Part 2 - Calibration)

Learn how to calibrate the MPU9250 in Python with the Raspberry Pi to get more accurate acceleration and gyroscopic...

Back to blog

Leave a comment

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