Access your Raspberry Pi anywhere, anytime with just a few clicks and secure it with SSL.

Learn how to set up remote access for your Raspberry Pi using SSH, VNC, or other methods. Secure your connection with SSL and keep your device safe from hackers. …


Updated August 26, 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 set up remote access for your Raspberry Pi using SSH, VNC, or other methods. Secure your connection with SSL and keep your device safe from hackers.

Introduction

Remote access to your Raspberry Pi is a powerful feature that enables you to control and monitor it from anywhere in the world as long as you have an internet connection. This can be particularly useful if you want to access your Pi when you are not at home or need to troubleshoot issues without physically accessing it.

There are several ways to achieve remote access, including SSH (Secure Shell), VNC (Virtual Network Computing), and NoMachine. In this article, we will focus on SSH and VNC. We will also discuss how to secure your connection with SSL for added protection.

Setting Up Remote Access using SSH

SSH (Secure Shell) is a protocol that allows you to remotely access your Raspberry Pi from another device, such as a laptop or smartphone. It provides a secure way of accessing the command line interface on your Pi and is commonly used for remote administration tasks. To set up SSH access follow these steps:

  1. Enable SSH on your Raspberry Pi:
    • Open the terminal on your Raspberry Pi and type sudo systemctl enable ssh. This will start the SSH service at boot.
    • Type sudo systemctl start ssh to start the service immediately.
  2. Find the IP address of your Raspberry Pi:
    • On the terminal, type hostname -I to display the local IP address of your device. Write it down as you will need it later.
  3. Set up port forwarding on your router:
    • Log in to your router’s administration interface (usually by typing its IP address into a web browser).
    • Locate the port forwarding settings and add a new rule that forwards TCP connections from an external port (e.g., 222) to the local IP of your Raspberry Pi on port 22.
  4. Connect to your Raspberry Pi using SSH:
    • On another device, open a terminal or command prompt and type ssh pi@<your_raspberry_pi_ip>, replacing <your_raspberry_pi_ip> with the IP address you wrote down earlier. You will be prompted to enter your Raspberry Pi’s password.
  5. (Optional) Generate an SSH key pair:
    • To enhance security, consider generating a public-private key pair for authentication. This allows you to connect without entering a password each time.
    • On the device you want to use for remote access, type ssh-keygen and follow the prompts to generate a new key pair.
    • Copy your public key to the Raspberry Pi by typing ssh-copy-id pi@<your_raspberry_pi_ip>.
    • You can now connect using ssh pi@<your_raspberry_pi_ip> without being prompted for a password.

Setting Up Remote Access using VNC

VNC (Virtual Network Computing) allows you to access your Raspberry Pi’s graphical desktop remotely. To set up remote access follow these steps:

  1. Install the necessary software on your Raspberry Pi:
    • Open a terminal and type sudo apt-get update followed by sudo apt-get install tightvncserver.
  2. Configure VNC server:
    • Type vncserver to start the VNC server configuration process. You will be prompted to set a password, which you will need for remote access.
  3. Find the IP address of your Raspberry Pi (if you haven’t already).
  4. Set up port forwarding on your router:
    • Log in to your router’s administration interface and add a new rule that forwards TCP connections from an external port (e.g., 59000) to the local IP of your Raspberry Pi on port 59000.
  5. Connect to your Raspberry Pi using VNC:
    • On another device, download and install a VNC client (such as TightVNC for Windows or Remmina for Linux).
    • Configure the client with your Raspberry Pi’s IP address and port (e.g., your_raspberry_pi_ip::59000).
    • Enter the password you set during VNC configuration to connect to your Raspberry Pi’s graphical desktop.

Securing Your Connection with SSL

SSL (Secure Sockets Layer) is a protocol that encrypts data transmitted between two devices, providing an additional layer of security for your remote connection. To secure your SSH or VNC connection using SSL follow these steps:

  1. Install the necessary software on your Raspberry Pi:
    • For SSH: sudo apt-get install stunnel4.
    • For VNC: sudo apt-get install x11vnc xorg.
  2. Generate a self-signed SSL certificate (replace <your_email@example.com> with your email address):
    • Type openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=<your_raspberry_pi_ip>" to create a new SSL certificate and private key.
    • Move the generated files to the stunnel or x11vnc configuration directory: sudo mv key.pem cert.pem /etc/stunnel/.
  3. Configure stunnel for SSH:
    • Edit /etc/stunnel/stunnel4.conf and add the following lines at the end of the file:
      [ssh]
      accept = 443
      connect = 22
      cert = /etc/stunnel/cert.pem
      key = /etc/stunnel/key.pem
      
    • Save and exit the file, then restart stunnel with sudo systemctl restart stunnel4.
  4. Configure x11vnc for VNC:
    • Edit /etc/x11vnc/x11vnc.conf and add the following line at the end of the file:
      ssl=1
      
    • Save and exit the file, then restart x11vnc with sudo systemctl restart x11vnc.
  5. Update your port forwarding rules on your router to forward external port 443 (or another port of your choice) to your Raspberry Pi’s local IP on port 443 for SSH or port 59000 for VNC.
  6. Connect to your Raspberry Pi using a secure connection:
    • For SSH, type ssh -p 443 pi@<your_raspberry_pi_ip> (replace <your_raspberry_pi_ip> with the IP address of your Raspberry Pi).
    • For VNC, configure your client to use port 59000 and connect as before. Note that some VNC clients may require additional configuration to use SSL. Consult their documentation for details.

Now you can securely access your Raspberry Pi from anywhere in the world using SSH or VNC. Just remember to keep your software up-to-date and your passwords strong to protect against hackers.