Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I can generate an OpenVPN static key by 'openvpn --genkey --secret myfile.key'. In python, I am currently using a shell call to generate a key, open the 'myfile.key' and read it back in. It would be much cleaner if I could do it without the shell call.

Does anyone know what type of key is generated with the --genkey command, or a way to generate the key directly in Python?

share|improve this question
up vote 1 down vote accepted

Unfortunately, OpenVPN doesn't currently provide Python APIs. However, one way to (slightly) clean up your script would be to have it generate the key directly to stdout, and then use the stdout returned by Popen.

openvpn --genkey --secret /dev/stdout


from subprocess import Popen, PIPE

proc = Popen("openvpn --genkey --secret /dev/stdout", shell=True, stdout=PIPE)
(stdout, stderr) = proc.communicate()

As far as I know, even though the keys are generated using the TLS PRF function, there's no "other" way to generate the keys.

share|improve this answer
facepalm Why didn't I think of writing to /dev/stdout? Thanks! – Aaron C. de Bruyn Dec 6 '10 at 4:51
Not a problem; happy to help! – Andrew M. Dec 6 '10 at 13:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.