I'm establishing an ephemeral hidden service via Tor, but I wish to reuse the same .onion address. I know to do this I must presist the same private-key every time I run the hidden service, but how do I do this?

I'm basically following the Stem documentation for python, but they don't tell you know to presist your private-key, just how to establish a hidden service.

I could use a non-ephemeral hidden service, but I would like be able to run my .py file to establish a hidden service via usb flash drive.

Any help would be greatly appreciated. Thanks!

2 Answers 2


Why not take a look here at the official docs ? It explicitly says, that key can be provided on creation. Of course, if you've already created an ephemeral hidden service, then no key or other stuff can be fetched, because it's the very meaning of it's ephemerical nature. Create your RSA1024 key and use it, why not?


Something similar to this.

from stem import control
controller = control.Controller.from_port(address=TOR_CONTROL_HOST, port=TOR_CONTROL_PORT)
key = 'raw-base64-of-the-rsa-1024-key-here'
onion = controller.create_ephemeral_hidden_service(ports=80, discard_key=True, await_publication=True, key_type='RSA1024', key_content=key)
if not onion.is_ok():
    raise Exception('Failed to publish onion.')

In my case loading the contents of 'key' from a file and if it wasn't there then generating a new one from tor itself by reading the results of publishing a totally ephemeral hidden service.

onion = controller.create_ephemeral_hidden_service(ports=80, discard_key=False, await_publication=True)
if not onion.is_ok():
    raise Exception('Failed to publish onion.')
for o in onion:
    if o != "OK":
        k, v = o.split('=', 1)
        if k == "PrivateKey":

You must log in to answer this question.