How to generate SSH key pairs with Python
Posted
by Lee
on Stack Overflow
See other posts from Stack Overflow
or by Lee
Published on 2010-03-17T22:35:40Z
Indexed on
2010/03/17
22:41 UTC
Read the original article
Hit count: 391
Hello, I'm attempting to write a script to generate SSH Identity key pairs for me.
from M2Crypto import RSA
key = RSA.gen_key(1024, 65337)
key.save_key("/tmp/my.key", cipher=None)
The file /tmp/my.key
looks great now.
By running ssh-keygen -y -f /tmp/my.key > /tmp/my.key.pub
I can extract the public key.
My question is how can I extract the public key from python? Using key.save_pub_key("/tmp/my.key.pub")
saves something like:
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADASDASDASDASDBarYRsmMazM1hd7a+u3QeMP
...
FZQ7Ic+BmmeWHvvVP4Yjyu1t6vAut7mKkaDeKbT3yiGVUgAEUaWMXqECAwEAAQ==
-----END PUBLIC KEY-----
When I'm looking for something like:
ssh-rsa AAAABCASDDBM$%3WEAv/3%$F ..... OSDFKJSL43$%^DFg==
© Stack Overflow or respective owner