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
-
Install Tor.
apt install tor # Debian, Ubuntu pacman -S tor # Arch xbps-install -S tor # Void -
Open
/etc/tor/torrcin an editor, as root. -
Uncomment these two lines:
HiddenServiceDir /var/lib/tor/hidden_service/ HiddenServicePort 80 127.0.0.1:80The 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:80on 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 on8080or3000, and you can add moreHiddenServicePortlines for more ports. -
Restart Tor, so it reads the new configuration:
systemctl restart tor # Debian, Ubuntu, Arch sv restart tor # runit rc-service tor restart # OpenRC -
Read your address:
sudo cat /var/lib/tor/hidden_service/hostnameA 56-character
.onionname. That is your site. Open it in the Tor Browser (with any other browser it will not resolve).
Notes worth knowing
sudois not optional in step 5. Tor creates the service directory with mode0700, owned by its own user. A normal user gets "Permission denied" on a file that plainly exists.- The address is a key pair. Alongside
hostnamesitsprivate_key. The address is the public key, so copying that directory to another machine moves the service with its name; losing it loses the address for good, and leaking it hands the address to someone else. Back the directory up, and keep it out of any web root. - Anything on your local port becomes public — including
whatever else your web server serves. If that matters, point
HiddenServicePortat a separate port with its own virtual host, or run a second server for it. - Nothing else opens up. Your firewall stays as it is, no inbound port is needed, and the machine can sit behind NAT the whole time.
- It is not a mirror. The
.onionaddress serves your site over Tor; your clearnet address, if you have one, is untouched.
Sources
- community.torproject.org/onion-services/setup — the project's own walkthrough of setting up an onion service, of which the five steps above are the short version.
- …/setup/install — installing Tor itself, per platform.
- torrc(5) — every directive in
torrc, including theHiddenService*family and what the port mapping really means. - tb-manual.torproject.org — the Tor
Browser manual: how to reach an
.onionaddress at all.