Build a Raspberry Pi Server: Access From Anywhere Guide

Unlock the full potential of your Raspberry Pi with our in-depth guide to creating a robust, remotely accessible Linux server. Learn how to install Ubuntu Server 24.04 LTS, configure secure SSH access, and set up Cloudflare Tunnel for seamless remote connectivity. Perfect for home labs, IoT projects, and budget-friendly cloud hosting alternatives. Discover how to turn your Raspberry Pi into a versatile, always-on server accessible from anywhere in the world.

By FabricSoul

Introduction

This guide will walk you through the process of setting up a Raspberry Pi as a Linux server. We’ll cover hardware requirements, OS installation, and configuration steps, including remote access setup.

Hardware Requirements

To set up your Raspberry Pi as a Linux server, you’ll need:

Note: Other single-board computers like Orange Pi or Banana Pi can also be used with similar steps.

OS Installation

Follow these steps to install the Linux server OS on your Raspberry Pi:

  1. Download the latest version of Ubuntu Server 24.04 LTS for ARM architecture from the official Ubuntu website.

  2. Insert the MicroSD card into your computer using the card reader.

  3. Use Raspberry Pi Imager to flash the Ubuntu Server image to the MicroSD card:

    a. Select Ubuntu Server 24.04 LTS as the OS to write to the MicroSD card. Raspberry Pi Imager

    b. Click “Edit Settings” to configure hostname, password, and SSH: Raspberry Pi Imager Settings

    • In the “General” tab, set a custom hostname and password. Raspberry Pi Imager Settings General

    • In the “Services” tab, enable SSH and add your public SSH key:

      Generate an SSH key (if you don’t have one) using:

      ssh-keygen -t ed25519 -C "[email protected]"
      

      SSH Keygen

      Enter a passphrase to secure the key (or press enter to skip). SSH Keygen Passphrase

      Copy your public key:

      cat ~/.ssh/id_ed25519.pub
      

      Paste the key into the “Services” tab of Raspberry Pi Imager. Raspberry Pi Imager Settings Services

    c. Save the settings and write the image to the MicroSD card.

  4. Insert the MicroSD card into the Raspberry Pi.

  5. Connect the Raspberry Pi to a monitor via HDMI and attach the power supply.

  6. Wait for the installation to complete. You can then log in using the keyboard and monitor or SSH. Login

  7. To find your Raspberry Pi’s IP address, log in and run:

    hostname -I
    
  8. Connect to your Raspberry Pi via SSH:

    ssh username@[IP_ADDRESS] -i ~/.ssh/id_ed25519
    

Configuration

After installing Ubuntu Server, perform these configuration steps:

Disable Password Authentication

  1. Open the SSH configuration file:

    sudo nano /etc/ssh/sshd_config
    
  2. Find and change the following line:

    #PasswordAuthentication yes
    

    to:

    PasswordAuthentication no
    
  3. Save the file and restart the SSH service:

    sudo systemctl restart ssh
    

Update the System

sudo apt update && sudo apt upgrade -y

Set Up Cloudflare Tunnel for Remote Access

  1. Create or log into your Cloudflare account.

  2. Add your domain in the “Websites” tab if you haven’t already.

  3. Navigate to the “Zero Trust” tab, then “Networks” > “Tunnels” to create a new tunnel. Cloudflare Tunnel

  4. Choose “Cloudflared” as the connector and click “Next”. Cloudflare Tunnel Connector

  5. Name your tunnel.

  6. Select “Debian” as the OS and “arm64-bit” as the architecture. Run the provided command on your Raspberry Pi to install the Cloudflared connector. Cloudflare Tunnel Setup

  7. Configure Public Hostnames by adding a subdomain and choosing “SSH” as the service with “localhost:22” as the destination. Cloudflare Tunnel Public Hostnames

  8. Save the tunnel configuration.

  9. Install Cloudflared on your local machine to enable Cloudflare Tunnel SSH connections.

  10. You can now connect to your Raspberry Pi from anywhere using the configured subdomain.

Conclusion

You’ve successfully set up your Raspberry Pi as a Linux server with remote access capabilities. Remember to keep your system updated and regularly review your security settings to ensure your server remains protected.

For troubleshooting or advanced configurations, refer to the official documentation for Ubuntu Server and Cloudflare Tunnel.