Hosting a Site as a Tor Hidden Service

Publish something running on your machine at its own .onion address — no public IP, no port forwarding, no certificate.

A hidden service is the easiest way to make a local site reachable from anywhere. You need no public address and no router configuration: Tor builds the path, and the address is the public half of a key pair that Tor generates for you. The other side of that coin is that it is only reachable through Tor.

The five steps

  1. Install Tor.

    apt install tor          # Debian, Ubuntu
    pacman -S tor            # Arch
    xbps-install -S tor      # Void
  2. Open /etc/tor/torrc in an editor, as root.

  3. Uncomment these two lines:

    HiddenServiceDir /var/lib/tor/hidden_service/
    HiddenServicePort 80 127.0.0.1:80

    The first is where Tor keeps the service's keys and address. The second maps a port: connections to port 80 on the onion address are forwarded to 127.0.0.1:80 on this machine. The left number is the port visitors use, the right one is where your site already listens — so this works just as well for a service on 8080 or 3000, and you can add more HiddenServicePort lines for more ports.

  4. Restart Tor, so it reads the new configuration:

    systemctl restart tor      # Debian, Ubuntu, Arch
    sv restart tor             # runit
    rc-service tor restart     # OpenRC
  5. Read your address:

    sudo cat /var/lib/tor/hidden_service/hostname

    A 56-character .onion name. That is your site. Open it in the Tor Browser (with any other browser it will not resolve).

Notes worth knowing

Sources