vagrant ssh not working in MobaXterm on Windows

2020-03-24 06:25发布

问题:

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:

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:

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.



回答3:

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.



回答4:

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



回答5:

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.