Secure Shell (SSH) is a widely used protocol for secure remote access to servers and other network devices. When working with SSH, it’s common to use key pairs for authentication, which consist of a private key and a corresponding public key. However, different tools and platforms may use different formats for these key pairs. In this tutorial, we’ll explore how to convert SSH key pairs between PuTTY and OpenSSH formats, allowing you to seamlessly use your existing keys across both Windows and Linux environments.
Introduction to SSH Key Pairs
Before diving into the conversion process, it’s essential to understand the basics of SSH key pairs. A key pair consists of two parts:
- Private Key: This is the secret part of the key pair that should be kept secure and not shared with anyone.
- Public Key: This is the public part of the key pair that can be freely shared without compromising security.
When you generate a key pair using PuTTYgen on Windows, it creates a private key in PuTTY’s proprietary format (.ppk
file) and a public key that can be used for authentication. However, OpenSSH, which is commonly used on Linux systems, uses a different format for its key pairs.
Converting Private Keys from PuTTY to OpenSSH Format
To convert your private key from PuTTY’s format to OpenSSH’s format, follow these steps:
- Open PuTTYgen: Start by opening PuTTYgen on your Windows system.
- Load Your Private Key: Click on "Load" and select your existing private key file (
.ppk
). - Export OpenSSH Key: Go to
Conversions
>Export OpenSSH key
and save the exported key with a name likeid_rsa
orid_dsa
, depending on the type of key you’re working with. - Copy the Private Key: Copy the exported private key to your Linux system, typically in the
~/.ssh/
directory.
Converting Public Keys from PuTTY to OpenSSH Format
If you only have a public key generated by PuTTYgen and need to convert it for use with OpenSSH, you can do so using the ssh-keygen
command on your Linux system:
ssh-keygen -i -f input_key.pub > output_key.pub
Replace input_key.pub
with the path to your PuTTY-generated public key file and output_key.pub
with the desired name for the converted public key.
Using Converted Keys with SSH-Agent and Keychain
After converting your key pairs, you can use them with tools like ssh-agent
and Keychain on Linux. These utilities allow you to securely store your decrypted private keys in memory, so you only need to enter your passphrase once per session.
- Start ssh-agent: Begin by starting the
ssh-agent
:eval $(ssh-agent -s)
- Add Your Private Key: Add your converted private key to the
ssh-agent
using:ssh-add ~/.ssh/your_private_key
- Configure Keychain (Optional): If you’re using Keychain, configure it according to its documentation to manage your SSH keys.
Tips for Seamless Use Across Windows and Linux
- Keep Your Private Keys Secure: Always keep your private keys secure. Never share them or store them in insecure locations.
- Use Strong Passphrases: Protect your private keys with strong passphrases to prevent unauthorized access.
- Regularly Review Authorized Keys: Periodically review the authorized keys on your servers to ensure no unwanted keys have been added.
By following this tutorial, you should now be able to convert your SSH key pairs between PuTTY and OpenSSH formats, enabling seamless use across both Windows and Linux environments. This compatibility ensures that you can leverage the security benefits of SSH key pair authentication regardless of the operating system you’re working with.