With client authorization switched on, an onion service's descriptor is encrypted to a list of specific client keys. Anyone else who has the address fetches the descriptor, can't decrypt the introduction point list, and gets nowhere. They can't connect, can't probe the web server, and can't even confirm the service exists. For an admin panel, an SSH endpoint, a home server or a small team's internal tool, that's a much stronger position than a login page.

The v3 design uses x25519 keypairs. The service holds the public halves, each client holds a private half. The v2 version of this feature was awkward enough that hardly anyone used it. The v3 one is fairly painless once you've done it once.

How it works under the hood

A v3 descriptor has two layers of encryption. The outer layer is keyed from the onion address, which is why HSDirs can't read descriptors but anyone with the address can. With client authorization enabled, the inner layer is encrypted with a random descriptor cookie, and that cookie is then encrypted separately to each authorized client's x25519 public key. A client with a matching private key can recover the cookie, decrypt the inner layer and read the introduction points. Everyone else sees a list of opaque client entries (padded, so the exact number of clients isn't obvious) and a blob they can't open.

The important point is that the protection kicks in before any connection to the service is made. A scanner hammering the address learns nothing, and a bug in your web app can't be reached by people who don't hold a key.

Generate a keypair

Keys are raw 32-byte x25519 values, base32-encoded without padding. The Tor community docs give an OpenSSL recipe, which works anywhere with OpenSSL 1.1 or newer and GNU coreutils:

openssl genpkey -algorithm x25519 -out alice.prv.pem

grep -v " PRIVATE KEY" alice.prv.pem | base64 -d | tail --bytes=32 \
  | base32 | sed 's/=//g' > alice.prv.key

openssl pkey -in alice.prv.pem -pubout | grep -v " PUBLIC KEY" \
  | base64 -d | tail --bytes=32 | base32 | sed 's/=//g' > alice.pub.key

That leaves you with two 52-character strings. On macOS, the stock tail and base32 differ; install coreutils or do it on a Linux box.

Ideally the client generates the keypair and sends only the public key to the service operator. In practice, small teams often have the admin generate both and hand over the private key through some secure channel. That works, but now the admin has everybody's private keys, which is worth being honest about.

Server side

Inside your HiddenServiceDir there's an authorized_clients/ directory, created empty when the service was first set up. Put one file per client in it. The filename must end in .auth; the part before is just a label for you.

/var/lib/tor/myservice/authorized_clients/alice.auth

Its contents are a single line:

descriptor:x25519:PUBLIC_KEY_BASE32_HERE

Fix ownership so tor can read it (on Debian, chown debian-tor:debian-tor), then reload:

sudo systemctl reload tor

As soon as there's at least one valid .auth file, the service switches into authorized mode. There's no separate torrc option to turn it on. That also means the reverse: delete the last file and the service is public again. If you ever empty that directory while tidying up, be aware of what you've done.

Check the log after reloading. A typo in the key or a stray space usually results in a warning that the file couldn't be parsed and is being skipped, and if it was the only client you've just accidentally gone public.

Client side, with the tor daemon

For command-line tools, SSH, or anything else using a system tor, tell tor where to find client keys in /etc/tor/torrc:

ClientOnionAuthDir /var/lib/tor/onion_auth

Create that directory (owned by the tor user, mode 700) and add a file ending in .auth_private:

/var/lib/tor/onion_auth/myservice.auth_private
<56-character-onion-address-without-suffix>:descriptor:x25519:PRIVATE_KEY_BASE32_HERE

The first field is the onion address without the .onion suffix. Reload tor, and connections to that address will now decrypt the descriptor automatically. The torrc options article has more on running tor as a client for other programs.

Client side, in Tor Browser

Tor Browser handles this interactively. Open the onion address and, instead of an error, you get a prompt with a key icon in the address bar asking for the private key. Paste the base32 private key, optionally tick the box to remember it, and the page loads. Saved keys can be viewed and removed under Settings, Privacy & Security, in the Onion Services Authentication section.

This is the friendliest route for non-technical people. Hand them the address and their private key over Signal or some other secure messenger, and that's the whole setup on their end.

Revoking access

Remove the person's .auth file and reload tor. The service publishes a fresh descriptor that no longer includes their entry, and once the old descriptor expires from the HSDirs (and from any cache the client still holds) they're out.

Two caveats. First, revocation only keeps them from finding the introduction points. If the person ever had shell access to the server, or a copy of hs_ed25519_secret_key, they can do whatever they like regardless. Second, a client that's already connected keeps its circuit until it closes. For a real "this person is now hostile" situation, I'd restart tor after removing the file rather than just reloading it, so existing rendezvous circuits get torn down too.

Where it fits

A few setups where this is the right tool:

  • SSH to a home machine without exposing port 22 to the internet. Add HiddenServicePort 22 127.0.0.1:22, authorize your laptop's key, and use torsocks ssh or a ProxyCommand.
  • Admin interfaces for a public onion site, run as a separate service with its own address and its own client keys.
  • Self-hosted apps (Nextcloud, a wiki, a home automation dashboard) for a household or a small group.

It's not a substitute for authentication inside the application. Treat it as an outer wall that keeps scanners and strangers off the property, and still lock the doors. And if you're thinking about a private service for many users, keep the descriptor size in mind: each authorized client adds an entry to a descriptor that has a fixed maximum size, and managing key files by hand gets old long before you hit that limit. For larger groups, an ordinary login behind a public onion is the more sensible design.

#client-authorization #x25519 #private-onion-service #torrc #access-control