1
votes

I'm using vagrant/VirtualBox on my Window (8.1) Laptop to start up a linux-test-vm from a Cygwin terminal... vagrant up, vagrant ssh, everything is working fine.

Now I want to work on that environment remotely from my main Linux-Workstation, so I've set up sshd in Cygwin and I can successfully ssh into my Windows-Box (same user as logged in locally in windows).

But when I cd'ed (via my remote ssh connection to windows-laptop) in my working directory and ran vagrant ssh, it tells me:

VM must be created before running this command. Run 'vagrant up' first

But I see the VM is running in VirtualBox GUI on Windows.

From this point on even locally on the Windows machine I can no longer interact with the running vagrant vm and the .vagrant (sub)directory has not files inside.


Same happens vice versa:

  • I stopped/deleted the VM in VirtualBox GUI
  • ran vagrant up via my ssh connection ... worked
  • ran vagrant ssh via my ssh connection ... works
  • but I do not see the VM in VirtualBox GUI on Windows
  • trying vagrant ssh locally on Windows ... same error again and .vagrant directory gets cleared

So I assume the Cygwin/sshd connection creates some sort of different Sessions that do not share the same "instance" of VirtualBox.

Is there any chance to share VirtualBox/vagrant environment between the local Windows and remote ssh session ???

WORKAROUND:

  • export ssh-config on the windows host: vagrant ssh-config > ssh_config
  • from the cygwin/ssh jump into the VM: ssh -F ssh_config default
  • never run any vagrant command from the cygwin/ssh connection
1

1 Answers

0
votes

Vagrant has a built-in solution since the 1.7.x versions called vagrant share which also allows you to remote into a box directly (bypassing the Windows host abstraction). It is generally used for the HTTP feature (eg. to show clients or others on a project the current state of work) but there is the ability to connect to any service running on any port. From the docs:

Just call vagrant share. This will automatically share as many ports as possible for remote connections. If the Vagrant environment has a static IP or DNS address, then every port will be available. Otherwise, Vagrant will only expose forwarded ports on the machine.

Note the share name at the end of calling vagrant share, and give this to the person who wants to connect to your machine. They simply have to call vagrant connect NAME. This will give them a static IP they can use to access your Vagrant environment.

Note to use vagrant share you need a (free) account with hashicorp.