Converting SSH2 Public Keys for Use in authorized_keys

When working with SSH keys, you may encounter different formats depending on the tool that generated the key. For example, PuTTYgen and older Windows tools often produce keys in the SSH2 public key format, which looks like this:

Linux and OpenSSH, however, expect a different format for the ~/.ssh/authorized_keys file. If you try to paste the above directly, SSH will reject it. Fortunately, converting between formats is straightforward.


Step 1: Save the SSH2 Key

Copy the entire block, including the BEGIN and END lines, into a file. For example:

Paste the contents, then save and exit.


Step 2: Convert to OpenSSH Format

Use the ssh-keygen tool to convert the key:

This tells ssh-keygen to import (-i) the SSH2 key and write the OpenSSH version into id_rsa_converted.pub.


Step 3: Inspect the Converted Key

Open the new file:

You’ll see a single line similar to this:

Notice the differences:

  • It begins with ssh-rsa
  • The key is one long Base64 string
  • The comment from the original file is preserved (zuser@example)

Step 4: Add to authorized_keys

Append the converted line into your server’s ~/.ssh/authorized_keys file:

Ensure the file permissions are correct:


Conclusion

If you receive an SSH2-style public key, you can’t use it directly with OpenSSH. By using ssh-keygen -i, you can quickly convert it into the proper authorized_keys format and enable secure key-based authentication.

This simple conversion can save time when integrating keys generated by PuTTYgen or other legacy tools into your Linux environments.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.