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:
- 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.
- Open PuttyGen.
- Click the “Load” button next to “Load an existing private key file”.
- 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 (*.*)”.
- You will get a Putty Notice box saying that the foreign key was successfully imported. Click “OK”.
- 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.
- 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.
- Go back into Putty and enter your connection details, but do not click “Open” yet.
- 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”.
- Click “Browse” next to the bottom box labeled “Private key file for authentication”, find your newly created .ppk file, and click “Open”.
- If you just want to connect without saving the key and host information for this connection, click “Open” now.
- 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.
- 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).
- 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.
- You should now be logged in.
Thanks very much. It was really very helpful..
saved my day!
Thank you, it helped me !
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…
I had the same “Server refused our key” error, I finally gave up and just used `vagrant` as both username and password.
Indeed, saved my day!
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!