How to convert Putty .ppk key to OpenSSH format

Converting a Putty .ppk file to OpenSSH format requires the puttygen binary that can be installed as follows:

  • Linux: with your package manager, install PuTTY (or the more minimal PuTTY-tools):
    • Ubuntu sudo apt-get install putty-tools
    • Debian-like apt-get install putty-tools
    • RPM based yum install putty
    • Gentoo emerge putty
    • Archlinux sudo pacman -S putty
    • etc.
  • OS X: Install Homebrew, then run brew install putty

Place your keys in some directory, e.g. your home folder. Now convert the .ppk file to SSH keypairs.

To generate the private key:

$ puttygen id_rsa.ppk -O private-openssh -o id_rsa

and to generate the public key:

$ puttygen id_rsa.ppk -O public-openssh -o id_rsa.pub

Move these keys to ~/.ssh and make sure the permissions are set to private for your private key:

mkdir -p ~/.ssh
mv -i ~/id_rsa* ~/.ssh/
chmod 400 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub

The above permissions are based on man ssh, i.e.:

 ~/.ssh/id_rsa
         Contains the private key for authentication. These files contain sensitive 
         data and should be readable by the user but not accessible by others 
         (read/write/execute). ssh will simply ignore a private key file if it is
         accessible by others. It is possible to specify a passphrase when generating 
         the key which will be used to encrypt the sensitive part of this file using 3DES.

 ~/.ssh/identity.pub
 ~/.ssh/id_dsa.pub
 ~/.ssh/id_ecdsa.pub
 ~/.ssh/id_rsa.pub
         Contains the public key for authentication. These files are not sensitive and 
         can (but need not) be readable by anyone.

Source: