The Ultimate Guide to Remote Accessing Your Raspberry Pi

Learn how to access your Raspberry Pi from anywhere using SSH and set up port forwarding on your router. …


Updated August 23, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to access your Raspberry Pi from anywhere using SSH and set up port forwarding on your router.

SSH, or Secure Shell, is a protocol used for secure remote access to computers and devices over an unsecured network like the internet. By default, Raspberry Pi OS enables SSH connections, allowing you to control your Raspberry Pi remotely from another device on the same local network. But what if you want to access your Pi from anywhere in the world?

To do this, you need to set up port forwarding on your router and configure your Raspberry Pi to accept incoming connections from external IP addresses. Here’s a step-by-step guide:

  1. Enable SSH on Your Raspberry Pi

First, make sure that SSH is enabled on your Raspberry Pi. Open the terminal and run:

sudo systemctl enable ssh
sudo systemctl start ssh
  1. Find Your Raspberry Pi’s IP Address

You need to know your Raspberry Pi’s local IP address so you can access it from your router’s configuration page. Open the terminal and run:

hostname -I

This will display your device’s IP address, something like 192.168.1.10. Write it down as you’ll need it later.

  1. Set Up Port Forwarding on Your Router

Log in to your router’s administration page using a web browser (typically by entering its IP address, such as 192.168.1.1, into the URL bar). Look for the section on port forwarding and add a new rule:

  • Protocol: TCP
  • External start port: 22222 (or any other unused port number)
  • Internal IP address: Your Raspberry Pi’s local IP address (e.g., 192.168.1.10)
  • Internal port: 22 (the default SSH port)
  1. Configure Your Raspberry Pi to Accept External Connections

Open the terminal and edit the SSH configuration file with nano:

sudo nano /etc/ssh/sshd_config

Find the line that says Port 22 and change it to Port 22, 22222. Save and exit (press Ctrl + X, then Y and Enter).

Restart the SSH service for the changes to take effect:

sudo systemctl restart ssh
  1. Connect From Anywhere

Now you can connect to your Raspberry Pi from anywhere using an SSH client and your router’s public IP address (find it on a website like whatismyipaddress.com). Use the command:

ssh pi@your_router_public_IP -p 22222

Replace your_router_public_IP with your router’s public IP address and enter your Raspberry Pi username (default is pi) and password when prompted.

That’s it! You can now access your Raspberry Pi from anywhere in the world as long as you have an internet connection. Remember to keep your Raspberry Pi secure by using a strong password and only allowing trusted devices to connect to it.