Univers Libre

Convert SSH keys from a format to another

Written on 6 September 2017, 21:46 CEST
Tags: ssh.

An SSH key can be stored in multiple format. ssh-keygen from OpenSSH generates keys in its own format, but other SSH implementations can use other formats. PuTTY for example generates keys in RFC4716 format, which looks like this:

-----BEGIN RSA PUBLIC KEY-----
MIIBCgK349HFUE929fXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa
D1MVlcrYG6XRKfkcIFEO929JFNEJONBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw
luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB
o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV
gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH
Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
-----END RSA PUBLIC KEY-----

You can't simply copy-paste this in an authorized_keys file. Hopefully you can easily convert the public key from a format to another. This is done by I-do-about-anything-and-everything command, aka ssh-keygen:

$ ssh-keygen -i -m <format> -f input_key.pub > output_key.pub

-m specify the input key format among RFC4716 (the format used by PuTTY, this is the default if -m isn't specified), PKCS8 and PEM.