Connecting your Raspberry Pi remotely from anywhere with SSH

A step-by-step guide on how to enable remote access to your Raspberry Pi over the internet using SSH. …


Updated August 21, 2023

Need help with your Raspberry Pi?
Contact Me!

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


A step-by-step guide on how to enable remote access to your Raspberry Pi over the internet using SSH. SSH (Secure Shell) is a powerful tool that allows you to securely connect and interact with your Raspberry Pi remotely from anywhere in the world. In this article, we’ll show you how to set up remote access to your Raspberry Pi over the internet using SSH. Here are the steps:

  1. Enable SSH on your Raspberry Pi

    • Connect your Raspberry Pi to a monitor, keyboard and mouse or use a VNC client like TightVNC or NoMachine if you’re accessing it remotely.
    • Open the terminal (Ctrl + Alt + T).
    • Type sudo raspi-config and hit enter.
    • Navigate to “Interfacing Options” and select “SSH”.
    • Choose “Yes” when prompted to enable SSH.
    • Select “Finish” and exit the configuration tool.
  2. Find your Raspberry Pi’s IP address

    • Open the terminal (Ctrl + Alt + T).
    • Type hostname -I and hit enter. This will display your Raspberry Pi’s local IP address.
    • Note down this IP address, as you’ll need it to connect via SSH later on.
  3. Port forwarding

    • If your Raspberry Pi is behind a router, you’ll need to set up port forwarding. This allows incoming traffic from the internet to be directed to your Raspberry Pi.
    • Log in to your router’s admin interface (usually by typing its IP address into a web browser).
    • Find the “Port Forwarding” or “Virtual Server” section and add a new rule:
      • Protocol: TCP
      • External port: 22 (the default SSH port)
      • Internal port: 22
      • IP address of the device to forward to: your Raspberry Pi’s local IP address (from step 2)
    • Save and apply the changes.
  4. Generate an SSH key pair

    • On your local machine, open a terminal or command prompt.
    • Type ssh-keygen and hit enter. This will generate a new public/private key pair.
    • By default, the keys are saved in ~/.ssh/id_rsa (private) and ~/.ssh/id_rsa.pub (public).
  5. Copy the public key to your Raspberry Pi

    • Use a tool like scp or WinSCP to copy the public key to your Raspberry Pi:
      • scp ~/.ssh/id_rsa.pub pi@<raspberry-ip>:~/.ssh/authorized_keys
        • Replace <raspberry-ip> with your Raspberry Pi’s IP address.
    • Enter the password for your Raspberry Pi when prompted.
  6. Test the connection

    • Open a terminal or command prompt on your local machine.
    • Type ssh pi@<raspberry-ip> and hit enter.
    • Replace <raspberry-ip> with your Raspberry Pi’s IP address. You won’t be prompted for the password anymore, as you now have SSH access to your Raspberry Pi.

Now you can remotely connect to your Raspberry Pi over the internet using SSH. Remember, always keep your Raspberry Pi and its software up-to-date to protect against security threats.