4

I have already found "SSH to Vagrant box in Windows" and added the git bin directory to my windows PATH. I verified that it worked by starting CMD and typing ssh, and got a usage message. (Before adding the git bin directory to my path, CMD complained that ssh wasn't a valid command.)

However...when I run vagrant ssh from MobaXterm, I get the same error I did before. (A page full of ruby errors that aren't helpful to me.) When I run it as VAGRANT_LOG=debug vagrant ssh, I see:

INFO subprocess: Starting process: ["C:\\Users\\(myname)\\DOCUME~1\\MOBAXT~1\\slash\\bin/ssh.EXE"]

This is the wrong ssh executable; it's the one installed in MobaXterm and it doesn't work if run from a CMD window.

How can I get vagrant ssh to work as it should?

1
  • Downvoters, comments would be appreciated. I came here for help and I thought I explained my question pretty clearly....
    – Wildcard
    Commented Nov 24, 2015 at 3:38

5 Answers 5

13

Part of the trick is that I don't want to use the Windows PATH for arbitrary commands—not even for ssh, really. I want to use the versions in MobaXterm for everything. All I want is to be able to run vagrant ssh the same way I would on Linux or Mac.

The workaround I have been using, which I found somewhere online (but can't find the page again), is:

vagrant ssh-config > vagrant-ssh
ssh -F vagrant-ssh default  # Works exactly the way `vagrant ssh` should

"default" is the box name for a typical Vagrant environment with only a single vagrant box. If there is more than one box, replace "default" with the box name:

ssh -F vagrant-ssh host001  # Works the way `vagrant ssh host001` would on another system

This is a good workaround with minimal changes required to workflow. But I'd still like a way to get vagrant ssh working without needing the extra file in my vagrant directory.

2
  • 1
    Your comment was super helpful (and worked!). I wrapped those 2 lines in a function inside my .bashrc file and can now ssh into my VM with vagrantssh (no space)
    – Jay Dorsey
    Commented Jun 21, 2016 at 11:40
  • 1
    Thank you! Just what I needed.
    – rosstex
    Commented Apr 22, 2018 at 16:12
3

here you can find an explanation

In the documentation, this mention is in the "Terminal tab settings" section, so you will find this option in the "Terminal" tab.

Go to MobaXterm global settings window, then click on the "Terminal" tab and check the "Use Windows PATH environment". Note that if you are using a session, you will have to do the same in this session: edit your session, then go to the "Terminal settings" tab and check the "Use Windows PATH" option.

0
1

Call me crazy but what about doing this:

  • Setup Vagrant Virtualbox VM like normal
  • In MobaXterm, create a "Bash" shell integration with the working directory setup as the directory of the Vagrant directory for the specific VM you are doing this for (aka ... the directory where the Vagrantfile lives for this VM)
  • In the "Advance Shell Settings", use this command (adjust vagrant path to where ever your Vagrant is installed as MobaXterm bash sees it):

command /drives/c/HashiCorp/Vagrant/bin/vagrant ssh-config > vagrant-ssh-config && ssh -A -F vagrant-ssh-config default

Vagrant VM needs to be up for MobaXterm Bash entry for the VM to work. I just setup two Bash shell settings for two Vagrant Virtualbox VMs I created and it seems to work just fine.

Updated: I went a little further since I've figured this out .. at least for me I did :). I added additional CMD shell sessions MobaXterm for each of my Vagrant VM. These additional CMD shell sessions do Vagrant halt, up, and restart (combo of halt and up) commands against the VMs they are specific to. This is what restart looks like:

vagrant halt
vagrant up
set /p value="Press Enter to continue"
exit

The Startup Directory for the above session is, again, the directory where the Vagrantfile lives for this VM. Oh, and make sure that "Use Windows PATH" is checked in Terminal Settings.

MobaXterm Sessions for Vagrant VMs

0
0

you can install git (https://git-scm.com/downloads) during install git choose "use git and optional Unix tools from the windows command prompt"

0

Download msysgit from msysgit project page and include msysgit/bin folder to PATH, now you can run ssh and vagrant ssh form your terminal on windows.

Not the answer you're looking for? Browse other questions tagged or ask your own question.