Putty Unable to Use Vagrant’s Private Key

I ran into an issue where I was attempting to use Vagrant on Windows and needed to SSH into the box. When I tried to run “vagrant ssh”, I got a message saying:

`ssh` executable not found in any directories in the %PATH% variable.

It then gives some instructions for using Putty. I knew Putty was installed on this Windows box, so I pulled it up and fed in the specs it gave (host, port, username, and private key). However, when I tried to connect, I got the following error message:

Unable to use key file “C:\Users\etucker\.vagrant.d\insecure_private_key” (OpenSSH SSH-2 private key)

I did some digging and found that you need to convert the vagrant private key file to a putty private key (.ppk) file. You can do that with PuttyGen:

  1. If you do not yet have PuttyGen installed (check first, because it is often installed with Putty), you can download it from: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
  2. Open PuttyGen.
  3. Click the “Load” button next to “Load an existing private key file”.
  4. When the dialog box opens to find the existing private key file, navigate to the directory where your vagrant private key is stored (usually in C:\Users\<yourUser>\.vagrant.d\). You may have to adjust the files that are being displayed using the drop-down next to the “File name:” box as it may only be displaying .ppk files, and you need it to be displaying “All Files (*.*)”.
  5. You will get a Putty Notice box saying that the foreign key was successfully imported. Click “OK”.
  6. You will now see the “Key fingerprint” and “Key comment” boxes are filled in. Beneath these two boxes are the “Key passphrase” and “Confirm passphrase” boxes. Enter your desired password for the key here.
  7. Click “Save private key” next to “Save the generated key” and choose where you would like to save the key and what you would like to call it.
  8. Go back into Putty and enter your connection details, but do not click “Open” yet.
  9. In the “Category” box on the left, click the plus sign next to “Connection” (if it is not already expanded), and then the plus sign next to “SSH”, and then click on “Auth”.
  10. Click “Browse” next to the bottom box labeled “Private key file for authentication”, find your newly created .ppk file, and click “Open”.
  11. If you just want to connect without saving the key and host information for this connection, click “Open” now.
  12. If you want to save this information, click on “Session” in the left box labeled “Category”, make sure the “Host Name (or IP address)”, “Port”, and “Connection type:” are filled in. Then, enter a name for your saved session in the “Saved Sessions” box, and click “Save”. You can now click “Open” to connect and your connection information will be saved.
  13. When the connection window opens, you will get the “login as” prompt. Use the login name that Vagrant gave you (or that you assigned through Vagrant).
  14. At the password prompt, you should see that it is authenticating with a public key, and then it will ask you for the passphrase for your key. Enter the passphrase you entered into PuttyGen when you converted the private key.
  15. You should now be logged in.

8 thoughts on “Putty Unable to Use Vagrant’s Private Key”

  1. It worked one day… but when I tried it today, vagrant did not let me in. So I repeated the whole procedure but I always get a “Server refused our key” and then I am asked a password…

  2. I did not even remember having puttygen , although I spend most of my time in putty windows …. 🙂
    Your instructions worked right away – thanks a lot, saved me quite some time!

Leave a Reply

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