Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoconvert vagrant key #15

Closed
techtonik opened this issue Nov 4, 2014 · 18 comments · Fixed by #20
Closed

Autoconvert vagrant key #15

techtonik opened this issue Nov 4, 2014 · 18 comments · Fixed by #20

Comments

@techtonik
Copy link

If it is possible for plugin to have its own data then autoconverting a vagrant key to ppk will save a lot of time for many people.

@nickryand
Copy link
Owner

I would love to see a pull request that adds this functionality. It would save a bit of time. It may be better to wait until hashicorp/vagrant#2608 is released as part of Vagrant 1.7

@techtonik
Copy link
Author

Unfortunately, I still can't read Ruby code to understand where Vagrant plugin interface ends and where PuTTY interface begins.

@seal-ss
Copy link

seal-ss commented Jan 26, 2015

+1. I also thought about it as I now use Vagrant 1.7 and converting the key to PPK for every vagrant box is very awkward.
I'll think about making a PR...

@StefanScherer
Copy link

At least the plugin already looks for the ppk beside the auto generated key of Vagrant 1.7:

Unable to use key file "C:/Users/stefan.scherer/GitHub/plossys/vagrant/ubuntu-intellij/.vagrant/machines/default/virtualbox/private_key.ppk" (unable to open file)
Using username "vagrant".
vagrant@127.0.0.1's password:

So only the automatic conversion step is needed.

I found this: http://webdevbyjoss.blogspot.de/2012/04/convert-openssh-keys-to-putty-on-linux.html
Tried it manually on Windows with

λ puttygen  "C:/Users/stefan.scherer/GitHub/plossys/vagrant/ubuntu-intellij/.vagrant/machines/default/virtualbox/private_key" -o  "C:/Users
/stefan.scherer/GitHub/plossys/vagrant/ubuntu-intellij/.vagrant/machines/default/virtualbox/private_key.ppk"

but there is a popup window:

  • PuTTYgen Notice
  • Successfully imported foreign key (OpenSSH SSH-2 private key). To use this key with PuTTY, you need to use the "Save private key" command to save it in PuTTY's own format.

It seems that puttygen.exe does not handle these command line options. Any ideas?

@StefanScherer
Copy link

This doesn't sound good:

So puttygen on Unix is not puttygen on Windows due to the GUI behaviour of C programs on Windows.This is a bit tricky, but solveable AFAIK. But then a PR or whatever is needed for the PuTTY gen project.

Another idea is to convert the SSH key to PPK natively with Ruby. We don't need everything of puttygen, just this conversion step.

Perhaps this code might help as a starting point: http://www.example-code.com/ruby/ssh_ppk_to_pem.asp

@nickryand
Copy link
Owner

I am totally open to this. I'll do some research when I can. I am open to a PR for this.

@StefanScherer
Copy link

I had a closer look at the Ruby gem chilkat. But rubygems.org is right, there is only a Mac and Linux version of it, but none for Windows. The platform we have the need for PuTTY conversion most.

I even checked it on a Windows machine with following command:

C:\Users\vagrant>vagrant plugin install chilkat
Installing the 'chilkat' plugin. This can take a few minutes...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:

Could not find gem 'chilkat (>= 0) x86-mingw32' in the gems available on this machine.

So it seems that it is nearly impossible to find a solution for Windows that is easier than helping the PuTTY team eg. reading id_rsa natively (as there is a conversion routine linked into puttygen.exe) or give the puttygen.exe the same command line option as for the Linux version.

For Mac and Linux there both is the chilkat gem, but also the command line tool puttygen.

@fkrull
Copy link
Contributor

fkrull commented May 18, 2015

So, I looked into that a bit and managed to get a rough solution working:

  1. compile the Unix puttygen for Windows (as puttygen-cmd)
  2. modify vagrant-multi-putty to use it
  3. ?
  4. profit

See https://bitbucket.org/fk/putty; there's a prebuilt version of puttygen-cmd in the Downloads section (or you can build it yourself, the "puttygen-cmd-windows" branch). I've also modified vagrant-multi-putty to use that program (if it's in your PATH) to convert OpenSSH keys if necessary (https://github.com/fkrull/vagrant-multi-putty/tree/convert-key). So, with that branch, you can just drop a puttygen-cmd into your PATH and vagrant putty should start autoconverting OpenSSH keys in most common situations.

I guess I'll have to present this to PuTTY upstream and see how that turns out before opening a pull request; in case the binary name has to change for example. Still, if you need this feature right now, you can have it.

@StefanScherer
Copy link

@fkrull Great approach! So if it is possible to build the command line tool on Windows to do the conversion, there should be also a way to integrate that into the puttygen.exe. I'll have a look at your branch.

@mightydok
Copy link

@fkrull thnx, works like a charm. Can you create pull request for this feature?

@fkrull
Copy link
Contributor

fkrull commented Nov 20, 2015

Sorry, that took longer than I planned, but I've now hit up the PuTTY guys to see if we can get this change upstreamed. I'll create a pull request when that is cleared up.

@nickryand
Copy link
Owner

Thanks for the follow up on this.

@fkrull
Copy link
Contributor

fkrull commented Feb 4, 2016

I can't really spend any more time chasing after PuTTY, so I opened a pull request now: #19.

@philr
Copy link
Contributor

philr commented Apr 2, 2016

I've created a library called PuTTY::Key that can handle the conversion of private keys to PuTTY's .ppk format. This requires only the Ruby OpenSSL standard library - it has no dependency on PuTTY or any of its related tools.

As an alternative to pull request #19, I've opened pull request #20 to handle automatic conversion using PuTTY::Key. This avoids the requirement for a new puttygen-cmd command line executable.

@nickryand
Copy link
Owner

This has been pushed! Thanks for this!!

https://rubygems.org/gems/vagrant-multi-putty/versions/1.5.0

@seal-ss
Copy link

seal-ss commented Apr 5, 2016

Works out of the box. Thank you very much!

@mightydok
Copy link

Thx, it works!

@bradisbell
Copy link

This is awesome! Vagrant is useful again! Thanks all!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants