简体   繁体   中英

vagrant ssh not working in MobaXterm on Windows

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?

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.

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.

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会话

你可以在安装git期间安装git( https://git-scm.com/downloads )选择“从windows命令提示符下使用git和可选的Unix工具”

msysgit项目页面下载msysgit并将msysgit/bin文件夹包含到PATH ,现在您可以在Windows上运行sshvagrant ssh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM