SSH Public-Private Key Format
- •
What it is
- •
SSH stores private keys in PEM format (
-----BEGIN RSA PRIVATE KEY-----, etc.). Public keys, however, use SSH's own single-line wire format instead:ssh-rsa <base64-encoded-key-blob> comment, designed to be easy to append as a line in a server's~/.ssh/authorized_keys.
- •
- •
When to apply
- •
A file starting with
ssh-rsa,ssh-ed25519, etc. (a.pubfile) needs to be converted before standard crypto libraries like PyCryptodome can parse it.
- •
- •
Worked example
- •
ssh-keygen -f id_rsa.pub -e -m pem > id_rsa.pemturns the one-linessh-rsa AAAA...format into a standard PEM block thatRSA.import_key()can read directly.
- •
- •
Python
- •
from Crypto.PublicKey import RSA # after: ssh-keygen -f key.pub -e -m pem > key.pem key = RSA.import_key(open("key.pem").read()) print(key.n)
- •
- •
Related
- •