I have a public key in the format:


Comment: "somename-20060227"


Usually I see keys in the format like this:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAqof[and so on]

Can I just copy the first key in the authorized_keys file or do I have to modify it somehow so it looks like the second one? I think the first one was generated by PUTTYgen while the second one was generated by ssh-keygen.


use ssh-keygen -i to convert SSH2-compatible format to OpenSSH compatible format.

from man ssh-keygen:

-i This option will read an unencrypted private (or public) key file in SSH2-compatible format and print an OpenSSH compatible private (or public) key to stdout. ssh-keygen also reads the RFC 4716 SSH Public Key File Format. This option allows importing keys from several commercial SSH implementations.

| improve this answer | |

You do have to convert the public key to openssh convention:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBmhLUTJiP[and so on]== somename-20060227

Also make sure that the key occupies exactly one line and no line breaks were introduced while copying.

| improve this answer | |

This is the complete, correct answer:

ssh-keygen -i -m PKCS8 -f public-key.pem

| improve this answer | |
  • 1
    "RFC4716" is the default key_format, and -m does appear to be for specifying the format of the INPUT in this instance, not the output, so you are correct. – JimNim Mar 28 '18 at 15:42
  • Technically alexus' "correct" answer is NOT wrong though, as that answer is not spelling out full syntax - only pointing to which primary flag should be used, leaving the need to check -i syntax/usage in the man page. – JimNim Mar 28 '18 at 15:48

Just rewrite your key in format suited for authorized_keys:

keytype keybody keyname

Keep in mind that trailing "==" are necessary placeholders to keep keylength equal to desired length.

| improve this answer | |
  • 4
    The trailing "==" are Base64 padding – Andrew Apr 18 '12 at 14:46
  • how do I know if its RSA or DSA? – Hans Apr 18 '12 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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