0
0
Iot-protocolsHow-ToBeginner · 4 min read

How to Access Raspberry Pi Over Internet: Simple Remote Access Guide

To access your Raspberry Pi over the internet, set up SSH on the Pi, configure your router to forward the SSH port (usually 22) to your Pi's local IP, and use a dynamic DNS service to handle changing public IP addresses. Then connect remotely using an SSH client with your public IP or domain name.
📐

Syntax

To connect remotely to your Raspberry Pi, you use the SSH command:

  • ssh [user]@[public_ip_or_domain] - Connects to your Pi using the username and public IP or domain.
  • ssh -p [port] [user]@[public_ip_or_domain] - Use this if you changed the default SSH port.

Before this, you must set up port forwarding on your router to forward external port (usually 22) to your Pi's local IP address and port.

Dynamic DNS services provide a domain name that updates automatically with your changing public IP.

bash
ssh pi@your-public-ip-or-domain
ssh -p 2222 pi@your-public-ip-or-domain
💻

Example

This example shows how to set up SSH access and connect remotely:

  • Enable SSH on Raspberry Pi with sudo systemctl enable ssh && sudo systemctl start ssh.
  • Find your Pi's local IP with hostname -I.
  • Log in to your router and forward port 22 to your Pi's local IP.
  • Sign up for a dynamic DNS service like No-IP or DuckDNS and set it up on your Pi.
  • From a remote computer, connect using ssh pi@your-ddns-domain.
bash
# Enable SSH on Raspberry Pi
sudo systemctl enable ssh
sudo systemctl start ssh

# Check local IP address
hostname -I

# Example SSH connection from remote
ssh pi@myraspberrypi.ddns.net
Output
pi@myraspberrypi:~ $ hostname -I 192.168.1.100 pi@remote-machine:~ $ ssh pi@myraspberrypi.ddns.net pi@myraspberrypi.ddns.net's password:
⚠️

Common Pitfalls

Common mistakes when accessing Raspberry Pi over the internet include:

  • Not enabling SSH on the Pi, so remote connections fail.
  • Forgetting to set up port forwarding on the router, blocking external access.
  • Using the local IP instead of the public IP or dynamic DNS domain when connecting remotely.
  • Ignoring security by leaving default passwords or open ports.

Always change the default password and consider using SSH keys for safer access.

bash
## Wrong: Trying to SSH using local IP from outside
ssh pi@192.168.1.100

## Right: Use public IP or dynamic DNS domain
ssh pi@your-ddns-domain
📊

Quick Reference

Summary tips for remote Raspberry Pi access:

  • Enable SSH on the Pi.
  • Set a strong password or use SSH keys.
  • Configure router port forwarding (default port 22).
  • Use dynamic DNS to handle changing public IPs.
  • Connect remotely with ssh pi@your-domain.

Key Takeaways

Enable SSH on your Raspberry Pi to allow remote connections.
Set up router port forwarding to forward SSH port to your Pi's local IP.
Use a dynamic DNS service to access your Pi with a stable domain name.
Always secure your Pi with strong passwords or SSH keys.
Connect remotely using the SSH command with your public IP or domain.