Host a Secure Tor Hidden Service on Raspberry Pi

Running a Tor hidden service (also known as an Onion Service) on a Raspberry Pi is an accessible, power-efficient, and practical way to host private websites, SSH interfaces, or chat servers. While the Raspberry Pi’s hardware is more than capable of running the Tor protocol smoothly, achieving true security requires systematic hardening of the operating system, network configuration, and web server to prevent IP address leaks and unauthorized access.

Why the Raspberry Pi Is Well-Suited for Tor

A Raspberry Pi functions as a dedicated, low-power server that can run continuously without significant electricity costs. Using a dedicated single-board computer provides physical and operational isolation from your daily workstations, reducing the risk that a compromise of your personal computer affects your hidden service, or vice versa.

1. Operating System Hardening

Security begins with the underlying operating system:

2. Installing and Configuring the Tor Service

Install Tor using the official repositories to ensure you have the latest stable release:

sudo apt install tor -y

To configure the hidden service, edit the main Tor configuration file located at /etc/tor/torrc. Add the following lines to map your service:

HiddenServiceDir /var/lib/tor/my_hidden_service/
HiddenServicePort 80 127.0.0.1:8080

This configuration tells Tor to route incoming requests directed at port 80 of your .onion address to port 8080 on the local loopback interface (127.0.0.1).

Restart the Tor daemon to generate your service keys and hostname:

sudo systemctl restart tor
sudo cat /var/lib/tor/my_hidden_service/hostname

Protect the /var/lib/tor/ directory permissions to ensure that only the debian-tor user can read the private keys.

3. Web Server Configuration and IP Leak Prevention

Application-layer misconfigurations are the most common cause of hidden service deanonymization. When configuring a web server like Nginx or Lighttpd:

4. Critical Best Practices for Ongoing Security