Control Your Raspberry Pi Remotely with These Simple Steps

Learn how to send commands to your Raspberry Pi from anywhere in the world using SSH (Secure Shell) and a dynamic DNS service. …


Updated August 25, 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 send commands to your Raspberry Pi from anywhere in the world using SSH (Secure Shell) and a dynamic DNS service.

Prerequisites:

  • A Raspberry Pi with an internet connection
  • An internet-accessible device (computer, tablet, or smartphone)

Step 1: Enable SSH on your Raspberry Pi

  1. Open the terminal on your Raspberry Pi and type sudo raspi-config to open the Raspberry Pi configuration tool.
  2. Navigate to “Interfacing Options” > “SSH” and enable it by selecting “Yes”.
  3. Exit the configuration tool and reboot your Pi with sudo reboot.

Step 2: Find Your Raspberry Pi’s IP Address

  1. Open a terminal on your local network (on the same WiFi as your Pi) and type hostname -I to display your Pi’s local IP address.
  2. Write down this IP address, as you will need it later.

Dynamic DNS allows you to access your Raspberry Pi using a domain name instead of an IP address, making it easier to remember and more reliable even if your IP changes. Here’s how to set up dynamic DNS with DuckDNS:

  1. Go to duckdns.org and sign up for a free account.
  2. Copy the token generated on the website (should look like “abcdefgh-12345678-90abcedf123456789”).
  3. On your Pi, open the terminal and run sudo apt update && sudo apt install duckdns.
  4. Create a new file called duckdns in /etc/cron.hourly with the following content:
#!/bin/sh
/usr/bin/curl -o /dev/null -s "https://www.duckdns.org/update?domains=YOURDOMAIN&token=YOURTOKEN"

Replace YOURDOMAIN with your duckdns subdomain (e.g., mynicepi.duckdns.org) and YOURTOKEN with the token from step 2. 5. Make the file executable: sudo chmod +x /etc/cron.hourly/duckdns. 6. Wait for an hour or run sudo /etc/cron.hourly/duckdns to update your IP address on DuckDNS. 7. You can now use YOURDOMAIN.duckdns.org instead of the local IP address when connecting to your Pi remotely.

Step 4: Connect to Your Raspberry Pi Remotely

  1. On your internet-accessible device, open a terminal or SSH client (e.g., PuTTY for Windows).
  2. Type ssh pi@YOUR_RASPBERRYPI_IP (or ssh pi@YOURDOMAIN.duckdns.org if you set up dynamic DNS) and press Enter. Replace YOUR_RASPBERRYPI_IP with the IP address or domain name of your Raspberry Pi.
  3. When prompted, enter the password for the “pi” user (default is “raspberry”).
  4. You are now connected to your Raspberry Pi remotely! Type commands as you would on a local terminal.

Remember, if you’re using dynamic DNS, you can use ssh pi@YOURDOMAIN.duckdns.org instead of the IP address to connect securely to your Pi from anywhere in the world. Keep your Raspberry Pi safe by enabling SSH only when necessary and regularly updating its software with sudo apt update && sudo apt upgrade.