Skip to content

Instantly share code, notes, and snippets.

@haf
Created May 31, 2012 14:19
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save haf/2843680 to your computer and use it in GitHub Desktop.
Save haf/2843680 to your computer and use it in GitHub Desktop.
Get SSH working on Vagrant/Windows/Git

If you are using vagrant, you probably-statistically are using git. Make sure you have its binary folder on your path, because that path contains 'ssh.exe'.

Now, modify C:\vagrant\vagrant\embedded\lib\ruby\gems\1.9.1\gems\vagrant-1.0.3\lib\vagrant\ssh.rb to comment out the faulty Windows check and add a real SSH check:

# if Util::Platform.windows?
  # raise Errors::SSHUnavailableWindows, :host => ssh_info[:host],
                                       # :port => ssh_info[:port],
                                       # :username => ssh_info[:username],
                                       # :key_path => ssh_info[:private_key_path]
# end

which = Util::Platform.windows? ? "where ssh >NUL 2>&1" : "which ssh >/dev/null 2>&1"
raise Errors::SSHUnavailable if !Kernel.system(which)

Now you can do vagrant ssh. Happy camper again!

@michfield
Copy link

Thanks. Confirmed working.
Using ssh.exe from git/bin directory.

@haf
Copy link
Author

haf commented Oct 26, 2012

For Ruby 1.9.3 and Vagrant 1.0.5 when installing through gems, this is where the file is:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/vagrant-1.0.5/lib/vagrant/ssh.rb

on line 57.

@franzliedke
Copy link

Awesome, works for me, too!

@rsgoheen
Copy link

rsgoheen commented Jan 2, 2013

In Vagrant 1.0.6, the location of this file is now:

C:\vagrant\vagrant\embedded\gems\gems\vagrant-1.0.6.dev\lib\vagrant\ssh.rb

@michfield
Copy link

Find the location of a file

    for /f "tokens=*" %f in ('where /R "c:\vagrant" "ssh.rb" ^| grep "embedded\\\lib\\\ruby\\\gems\\\.*\\\gems\\\vagrant.*\\\lib\\\vagrant\\\ssh.rb"') do @(set _TMP=%f)

And patch that `ssh.rb` file

    (
    echo/57a58
    echo/^> =begin
    echo/65a67,71
    (echo/^> )
    echo/^> =end
    (echo/^> )
    echo/^>       which = Util::Platform.windows? ? "where ssh >NUL 2>&1" : "which ssh >/dev/null 2>&1"
    echo/^>       raise Errors::SSHUnavailable if !Kernel.system^(which^)
    ) >vagrant-ssh-windows-patch.diff

    patch -i vagrant-ssh-windows-patch.diff "%_TMP%"

And remove residues.

    del vagrant-ssh-windows-patch.diff

SSH in Vagrant will now work as supposed to:

    vagrant ssh

@vitor-e-caetano
Copy link

Thx dude! Worked!

@avitevet
Copy link

Worked for me too.

Just to document a dead end: originally I tried to keep the git/bin dir out of my PATH env var, and changed the "where ..." command to "where /R <git/bin directory>." This got me past the "ssh unavailable" error, but later the script couldn't find my ssh.exe. I ultimately just added the git/bin dir to my PATH.

@nguyenqmai
Copy link

tks man! Worked!!!!!

@tcmaynard
Copy link

Using Vagrant version 1.1.5 adding C:\Program Files (x86)\Git\bin to the PATH is sufficient. The patch above must already be present in the Vagrant code.
vagrant ssh
Works as documented on Windows 7 Home Premium SP1.

@gabrielhpugliese
Copy link

Another way to get it working is just set PATH in the cmd.exe you have opened:

set PATH=%PATH%;C:\Program Files (x86)\Git\bin

Then run vagrant ssh

Copy link

ghost commented Jun 20, 2013

I'm having no luck with vagrant 1.2.2, any ideas? I've tried both modifying the ssh.rb and altering my path, but to no avail.

@DanAtkinson
Copy link

Indeed, @gabrielhpugliese's answer" is the most effective, since it actually resolves the issue, rather than bypasses it. :-)

@eristoddle
Copy link

I have 1.5.1. The patch does not fit this version. I do have putty installed because I need it for other things. But I have the bin folder of Git in the path also. Still it finds putty, and shows this message.

@api42
Copy link

api42 commented Sep 2, 2014

@gabrielhpugliese .. Thanks a lot !!!

@MorbetMacErp
Copy link

Answer from @gabrielhpugliese seems to be the best solution, works fine for me.

@phillijw
Copy link

Vagrant 1.6.5 has the file at: C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.6.5\lib\vagrant\util\ssh.rb

@DimitarVoynov
Copy link

Thanks phillijw!

@victorhtorres
Copy link

Hi guys,

I have installed vagrant 1.7.4 and VBox 5x and all was working well but after of update git 1.9.x to the last version 2.7.0 on windows and now the ssh is not working. I put the path variable and I changed the code like the example here but without result and I think the solution to change the ssh.rb is not the same for the last version on vagrant.

I appreciated any help. Thanks!

@jessev123
Copy link

Vagrant 1.8.1 file is moved yet again - C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.1\lib\vagrant\util

@nsawit
Copy link

nsawit commented Jan 28, 2016

please help, i'm just starting to learn Drupal 8. I'm stuck in running 'vagrant ssh' command. I'm still getting 'ssh executable not found in any direct SSH client installed? Try installing Cyg contain an SSH client. Or use your favor authentication information shown below:'. As I read comments above, one recommendation is to set the PATH to '%PATH%;C:\Program Files (x86)\Git\bin' .. However, I check the directory and I've noticed that there's no such ssh.exe file in any directory in my computer. So i was thinking I need to download and install that ssh.exe . I've searched on the internet and downloaded the one from Git.. Now that I've installed it and verified that ssh.exe is now existing in the directory , i've set the path but still stuck in the same error. :(

please refer to the attached screenshot
ssh

@julianfrank
Copy link

Try adding the path D:\Program Files\Git\usr\bin

@ITedInnovator
Copy link

Thanks Julian Frank but for me it was the C drive:
set PATH=%PATH%;C:\Program Files\Git\usr\bin

@victorhtorres
Copy link

The route C:\Program Files\Git\usr\bin works fine for me. The first solution should not be necessary.

@charlesaraya
Copy link

Adding C:\Program Files\Git\usr\bin worked for me too.

@SnehaSahu05
Copy link

..git\usr\bin works perfect, the previous solution ..git\bin is not needed as path variable.
thanks @rekestas

@sagaroe
Copy link

sagaroe commented Dec 29, 2016

Added "C:\Program Files\Git\usr\bin" in PATH and it worked for me. thanks :)

@jameszrx
Copy link

jameszrx commented Apr 9, 2017

Git\usr\bin works for me too! Excellent solution! Thanks a lot!

@karan1276
Copy link

Yup "C:\Program Files\Git\usr\bin" works, Thanks :)

@cancerberoSgx
Copy link

In my case even adding ssh to the PATH didn't solve the problem. What I had to do is connect to vagrant with ssh manually. After executing vagrant up, instead of executing vagrant ssh, I do this:

ssh vagrant@127.0.0.1 -p 2222
And the password is "vagrant"

For getting all the information about the ip, port and user you can use

vagrant ssh-config
Ope this helps somebody...

@marcosronaldo
Copy link

@cancerberoSgx Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment