If your Tor onion service’s private key is compromised, you must immediately rotate the key, update the service, and investigate how the leak occurred, because anyone with the key can impersonate your site and intercept its traffic. This guide covers the concrete steps to contain the damage, generate a new key, and reduce the risk of future compromise.
Background: What an Onion Private Key Is
An onion service (formerly “hidden service”) runs on the Tor network and is identified by a 56-character address ending in .onion. That address is derived from the service’s public key using a one-way hash. The corresponding private key—a 64-character base32 string stored in a file named hs_ed25519_secret_key—is what proves to the Tor network that you control the address. With the private key, anyone can:
- Set up a new service on the same address, effectively hijacking your identity.
- Decrypt traffic sent to your old service if they also captured the network traffic (though Tor’s end-to-end encryption usually prevents this).
- Publish malicious content under your trusted address, damaging your reputation and harming users.
Immediate Steps to Contain the Damage
- Take the service offline – Stop the Tor process or disable the onion service configuration to prevent further abuse of the compromised key.
- Generate a new key pair – Run
tor --hash-passwordor use the control port to create a new key. The simplest method is to delete the oldhs_ed25519_secret_keyandhs_ed25519_public_keyfiles and restart Tor, which will generate a fresh key pair automatically. - Update your service – Replace the key files in your Tor data directory (usually
/var/lib/tor/your_service/on Linux). Restart Tor and verify the new.onionaddress appears in your logs. - Notify your users – Publish the new address on your website, social media, and any other channels. If you have a v3 onion service, you can use a “v3 onion service descriptor” to redirect old addresses, but this is not automatic.
- Investigate the leak – Check server logs, file permissions, and any backups to determine how the key was exposed. Common causes include insecure file permissions, backups stored in plaintext, or a compromised server.
How to Generate a New Onion Key
Tor’s v3 onion services use ed25519 keys. To generate a new key pair, you can:
- Manually delete the key files – Stop Tor, remove the
hs_ed25519_*files from your service directory, then start Tor again. It will create a new key and a new address. - Use the control port – With Tor running, use the
ADD_ONIONcommand to create a new service with a fresh key. For example, usingtor --controlport 9051and then sendingADD_ONION NEW:ED25519-V3via a control client. - Use a tool like
mkp2240– This is a vanity address generator, but it also creates new key pairs. However, it is not necessary for simply rotating a key.
After generating the new key, update your web server configuration to point to the new .onion address. If you use a reverse proxy, update any hostname references.
Common Problems and Misconceptions
Misconception: “I can just change the password on my onion service.” Onion services do not use passwords. The private key is the only credential. If it leaks, you must change the key itself.
Problem: “My old address is still active.” If the attacker already started a service on your old address, you cannot force it offline. You can only take down your own service and move to a new address. Users may still be directed to the malicious clone, so you must clearly communicate the change.
Problem: “I don’t know how the key leaked.” Common vectors include:
- File permissions too open (e.g., world-readable key files).
- Backups stored on an unencrypted drive or in a cloud service.
- Server compromise via an unpatched vulnerability.
- Physical access to the server.
Preventing Future Compromise
- Use strong file permissions – The key file should be readable only by the Tor user (e.g.,
chmod 600). - Encrypt backups – If you back up the key, use a strong passphrase and store it separately from the server.
- Keep the server patched – Regularly update the operating system and Tor to fix known vulnerabilities.
- Use a dedicated user – Run Tor under a non-privileged user account to limit the impact of a web server compromise.
- Consider hardware tokens – For high-security services, store the key on a hardware security module (HSM) or a dedicated offline machine, though this is complex for most operators.
Costs and Effort of Key Rotation
Rotating an onion key is free in terms of money, but it has a significant operational cost: you lose your established address. Users who have bookmarked your old address will no longer reach you. For a small personal blog, that may be acceptable. For a large service with many users, the cost is high, which is why prevention is critical.
There is also a time cost: you must update any links, certificates (if you use HTTPS on the onion service), and possibly Tor Browser’s built-in exceptions. The process itself takes minutes, but the communication effort to inform users can take days.
Alternatives to Full Key Rotation
In some cases, you might not need to abandon the address entirely:
- If the key was exposed but not used – You can still rotate it, but the risk is lower. However, it is safer to treat any exposure as a full compromise.
- Use a “v3 onion service” with a subdomain – Some services use a single key for multiple subdomains. In that case, you only need to rotate the primary key, but all subdomains will change.
- Set up a redirect – After moving to a new address, you can keep the old service running (if you still control it) to display a notice and redirect users. This is only possible if the attacker hasn’t hijacked it.
Frequently Asked Questions
Q: How do I know if my onion private key is compromised?
Signs include users reporting that your site shows unexpected content, your service suddenly stops working, or you find unauthorized access to your server. There is no built-in alert, so you must monitor your service’s behavior and server logs.
Q: Can I recover my old .onion address after rotating the key?
No. The address is mathematically derived from the public key. If you change the key, you get a new address. There is no way to keep the same address with a different key.
Q: What is the difference between v2 and v3 onion keys?
v2 keys are 1024-bit RSA and produce 16-character addresses; v3 keys are ed25519 and produce 56-character addresses. v3 is more secure and is the current standard. If you are still using v2, you should upgrade to v3.
Q: Should I report the compromise to authorities?
That depends on your jurisdiction and the nature of your service. If you are running a legal service, you may want to report it to your local cybercrime unit. However, this is a personal decision, and there is no universal requirement.
Q: How can I back up my onion key securely?
Encrypt the key file with a strong passphrase (e.g., using GPG) and store it in a separate physical location. Never store it in plaintext on the same server or in a public cloud.
Conclusion
Compromise of an onion service private key is a serious incident that requires immediate action. Rotate the key, take the service offline, investigate the cause, and communicate with your users. While the loss of a known address is inconvenient, it is far better than allowing an attacker to control your identity. With proper file permissions, regular updates, and secure backups, you can significantly reduce the risk of recurrence.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Mac Start Up Automatically After Power Failure?
- Expose Self-Hosted Service Securely Without Cloudflare Tunnel
- Nano Delivery for Functional Foods: What It Can and Can’t Do4.00
- Disable Apple Watch Turn-by-Turn Vibration While Driving
- Convert Play FLAC in iTunes: Full Guide
- Soda Foundation Charter: What It Means