SSH to Vagrant box in Windows?
Solution 1
I use PuTTY to connect to my Vagrant boxes on Windows7.
Make sure you
- convert the
%USERPROFILE%\.vagrant.d\insecure_private_key
to .ppk using PuTTYGen - use the .ppk key in your PuTTY session - configured in Connection > SSH > Auth > Private key file
- use host
127.0.0.1
- use port 2222 instead of 22
- you can set the default username (vagrant) under Connection > SSH > Auth > Private key for authentication
Solution 2
You must patch some Vagrant code by modifying only one file, ssh.rb
.
All the info is here: https://gist.github.com/2843680
vagrant ssh
will now work also in Windows, just like in Linux.
EDIT: In newer Versions this became unnecessary. You still have to add the path to your ssh.exe
to your PATH
Variable:
Search for ssh.exe on your computer, copy the Path (i.e. C:\Program Files (x86)\Git\bin
), open System Preferences, find the Environment variable Settings, click on the Path Variable, add the path, separating the existing paths using ;
.
Solution 3
Another option using git binaries:
- Install git: http://git-scm.com/download/win
- Start Menu > cmd (shift+enter to go as Administrator)
set PATH=%PATH%;C:\Program Files\Git\usr\bin
vagrant ssh
Hope this helps :)
Just a bonus after months using that on Windows: use Console instead of the Win terminal, so you can always open a new terminal tab with PATH set (configure it on options)
Solution 4
Download Putty: http://www.chiark.greenend.org.uk/~sgtatham/putty/
Using putty.exe:
Putty GUI:
HostName: 127.0.0.1
Port: 2222
When you connect(Terminal Screen):
User: vagrant
Passwd: vagrant
Before you try to connect, verify your VM using cmd.exe:
vagrant status
If it is down use:
vagrant up
Solution 5
The accepted answer is really helpful however it may happen that instead of the following key:
%USERPROFILE%\.vagrant.d\insecure_private_key
a different key has to be converted to the Putty's format:
{vagrant_machine_root}/.vagrant/machines/default/virtualbox/private_key
Where {vagrant_machine_root}
is a folder with the Vagrantfile
of the machine we want to connect to using Putty.
As @ibizaman mentioned use vagrant ssh-config
to check what key is used by vagrant:
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile c:/dev/test/.vagrant/machines/default/virtualbox/private_key <-- HERE IS THE KEY YOU NEED TO CONVERT TO THE PUTTY FORMAT
IdentitiesOnly yes
LogLevel FATAL
Related videos on Youtube
Sathish
Updated on July 08, 2022Comments
-
Sathish almost 2 years
I'm using Vagrant to start a VirtualBox VM in windows. In other platforms, I can just
$ vagrant ssh
to connect to the VM.
How do i connect to this Vagrant box in windows?
The way suggested in Vagrant documentation to use PuTTy also did not work:
http://docs-v1.vagrantup.com/v1/docs/getting-started/ssh.html
-
Sliq over 10 yearsBig tutorial on this, featuring how to SSH into a Vagrant box in Windows 7/8
-
Omri Spector over 10 yearsThis is not an issue anymore. If you have ssh.exe in your path (e.g. c:\Program Files\git\bin), then 'vagrant ssh' works.
-
KCD over 9 yearsFYI Vagrant doesn't include ssh
due to licensing reasons. It seems possible but until a lawyer gives the go-ahead on this, we're not gong to do this.
Ship ssh.exe by default in the Windows installer ... it puzzled me
-
-
DGomez almost 12 yearsnote too: when the login as: prompt appears, enter 'vagrant' as the user name (without quotes).
-
Michael Field over 11 yearsAnd then do that for every VM in Vagrant. You know, Vagrant works with multiple VM's. So, just use the proper solution, not workaround: there is my answer below. Small patch in Vagrant.
-
Cory Dolphin over 11 yearsPlease comment on the Github pull request for the issue if you use this work around, it is time it got merged. github.com/mitchellh/vagrant/pull/933
-
Johann almost 11 yearsThis appears to have been merged about three months ago. It definitely exists in version 1.2.2.
-
RadiantHex almost 11 yearsSomeone upvote this answer. Was trying to figure out how I got this working, now I know! Thanks
-
Alex almost 11 yearsIs this still needed or patched in recent Vagrant dists?
-
Bartvds over 10 yearsThis worked fine for me. As I have GIT it works a lot cleaner then switching to Putty since you can just reuse the same console window.
-
Bartvds over 10 yearsThanks, but I now use conemu. It is similar but more flexible then Console. I have it wrapping many consoles, like cmd.exe, git bash and putty with alliases and other fancy stuff.
-
robertpateii over 10 years@Alex It's definitely patched into recent Vagrant versions. I tested it and documented it here: robertpate.net/blog/2013/…
-
sobi3ch over 10 yearsHow did you know you need to convert key to .ppk?
-
Dror Bereznitsky over 10 years@sobi3ch there are many resources explaining how to use your keys with Putty, for example meinit.nl/using-your-openssh-private-key-in-putty
-
mpen about 10 yearsYou can set the default username under
Connection > Data > Auto-login username
and the PPK setting is underConnection > SSH > Auth > Private key for authentication
-
Larry Silverman almost 10 yearsIf you prefer as I do to secure your private keys with passwords, it may be easier in the long run to use the pageant.exe app at startup, loading your ppk file into it. Then you enter your password to pageant once, and you can log in without having to specify the ppk password in the putty terminal every time.
-
ThorSummoner over 9 yearsWhy would you go though all that effort just to use PuTTY
-
ThorSummoner over 9 yearsIf you install git bash before vagrant, vagrant will add itself to the git bash path allowing it to use the git bash ssh from a git bash terminal.
-
ibizaman over 9 years@ThorSummoner to use x11 forwarding for example.
-
ibizaman over 9 yearsYou can use
vagrant ssh-config
to know what options to give to putty. -
ibizaman over 9 years@ThorSummoner not alone, but with XMing for example, it can.
-
Mark Liu over 9 yearsWhy was this voted now? It is a reasonable solution and if you want to dev in Windows, this is a great option, much better than hacking your putty, hacking your other commands.
-
Idan Gozlan over 9 yearsAnother thing to do before ready to use on putty with @ibizaman way, is to convert the private key to ppk with PuttyGen (import>save)
-
Janusz Skonieczny over 9 yearsQuickly set path to your git OpenSSH, open PowerShell and run:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;c:\Program Files (x86)\Git\bin\", "User")
-
Shani Elharrar about 9 yearsThe other answer that says to add ssh.exe to your path variable is preferred. less manual work needed.
-
icc97 about 9 yearsThis was by far the best solution for me. The link you give hasn't been updated since 2010. There is a more recent version available at mls-software.com/opensshd.html
-
David Soroko about 9 yearsYou will need to amen your PATH to include the Cygwin bin directory, something like
set PATH=%PATH%;c:\cygwin\bin
-
vladimir over 8 yearsfor Git 2.5.0 PATH should be "C:\Program Files\Git\usr\bin".
-
Wildcard over 8 yearsVery helpful. Still not working for me, probably because I'm using MobaXterm. I posted my follow-up question here: stackoverflow.com/q/33879568/5419599
-
dtbarne over 8 yearsWorks for me after I updated my path, although I had to restart to get it to stick for some reason.
-
v.babak about 8 yearsset PATH=%PATH%;C:\Program Files\Git\usr\bin Working perfect! Thanks!
-
johnzachary about 8 yearsIf you want to use Putty, then this is the best answer. You have to convert the correct private key. Many thanks!
-
appoll over 7 yearsThis shows perfectly how not to get lost in words. Amazing, thanks!
-
perlyking over 7 yearsWorth mentioning that you should check the
User
value and make sure you supply it to Putty in Connection->Data->Auto-login username. On my VM the name wasubuntu
and I had been repeatedly trying, and failing, to log in asvagrant
. -
perlyking over 7 yearsBest to check the output of
vagrant ssh-config
to make sure this is the correct user name: on my VM, ubuntu/xenial64, it wasubuntu
-
Neoraptor about 7 yearsThis is the best answer here. Cygwin will give you a bash like terminal to work with. Awesome!
-
Jared Beach about 7 yearsNot working for me. Do I need a password when running ssh-keygen?
-
mixel about 7 years@JaredBeach No, don't enter passphrase when generating key.
-
Bud Damyanov about 3 yearsIt is the correct answer, things(settings) were changed in years.