I first want to generate a service and save the private key for reuse if one hasn't already been generated and saved, and if one has been generated and saved I want to be able to load it again if possible, so I can reuse the onion address within my program.

Also I'm programming this with python and you can see my program so far if you'd like to have a look.

program link

1 Answer 1


You're using stem's create_ephemeral_hidden_service(), which allows you to specify the key to use for your onion service with the key_type and key_content arguments. You can either create the key manually before you first run the program, or the first time you run the program, you can allow create_ephemeral_hidden_service() to generate the key (make sure the discard_key option is False), parse the response from tor, save the PrivateKey field in the response, and then re-use this key in the future.

There is a code example here: https://tor.stackexchange.com/a/10483

  • I already had a look at that example sadly. The second example which allows me to get the generated keys didn't work. The first part only returns the hostname/onion address rather than the keys.
    – 404
    Dec 10, 2020 at 9:08
  • Okay you'll need to create the key manually then. I would have tor create a new onion service, copy the key, delete the service, and then re-use this key in the Python code.
    – Steve
    Dec 10, 2020 at 15:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .