New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Linux Subsystem on Windows #7731

Closed
thany opened this Issue Aug 17, 2016 · 32 comments

Comments

Projects
None yet
@thany

thany commented Aug 17, 2016

Vagrant version

Vagrant 1.8.5

Host operating system

Windows 10.0.14393

Guest operating system

Ubuntu 14.04.5 LTS

Expected behavior

Vagrant should be able to use Linux Subsystem on Windows 10 馃槑
Instead, it expects cygwin/mingw/git-bash. It's much more awesome, more up-to-date, more native, and well integrated. It makes total sense to use it when installed, especially considering Vagrant appears to be made exclusively for Linux and then ported (or something) to Windows.

Actual behavior

This error 鈽

`ssh` executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication information shown below:

Steps to reproduce

  1. Install the Windows 10 summer upgrade to build 14393 (also referred to as Version 1607)
  2. Try running vagrant ssh on any vagrant box. It doesn't matter at all which one.

References

Just to be absolutely clear, here's how to get Linux Subsystem (commonly referred to as Bash for Windows) and to clarify which is the one I mean:
http://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/

@cwt137

This comment has been minimized.

cwt137 commented Aug 17, 2016

+1

@chrisroberts chrisroberts added this to the 2.0.0 milestone Aug 17, 2016

@ricardowong

This comment has been minimized.

ricardowong commented Sep 30, 2016

@thany Install Mingw64's ssh and place it on the path (which is an option in git for windows install).

You can also use any ssh client (PuTTY, Powershell, Bash on Ubuntu), on port 2222 (or a different one set in the VagrantFile). The username/password is vagrant/vagrant and the generated key file can be found on .vagrant folder.

Related but out of the scope: installing Vagrant + VirtualBox is a no on Ubuntu on WSL.

@StefanScherer

This comment has been minimized.

Contributor

StefanScherer commented Sep 30, 2016

I also prefer Git for Windows with SSH in path.

But Windows 10 is becoming a weird melting point with Windows, Linux, Docker, etc. If someone wants to try it, first check if bash.exe is installed. This is after installing the "Windows Subsystem for Linux (Beta)", but Ubuntu is still missing.

Running the first bash it asks to download Ubuntu

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\windowsuser>where bash
C:\Windows\System32\bash.exe

C:\Users\vagwindowsuserrant>where ssh
INFO: Could not find files for the given pattern(s).

C:\Users\windowsuser>bash -c "ssh vagrant@1.2.3.4 hostname"
-- Beta feature --
This will install Ubuntu on Windows, distributed by Canonical
and licensed under its terms available here:
https://aka.ms/uowterms

Type "y" to continue: y
Downloading from the Windows Store... 100%
Extracting filesystem, this will take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: ubuntuuser
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
The environment will start momentarily...
Documentation is available at:  https://aka.ms/wsldocs
ssh: connect to host 1.2.3.4 port 22: Resource temporarily unavailable

Files from the Windows machine can be reached in the subsystem with /mnt/c/Users/windowsuser

To check if bash is installed and ssh is available in the subsystem you could check for C:\Users\windowsuser\AppData\Local\lxss\rootfs\usr\bin\ssh

C:\Users\windowsuser>dir C:\Users\windowsuser\AppData\Local\lxss\rootfs\usr\bin\ssh
 Volume in drive C is Windows 10
 Volume Serial Number is 4AEA-E267

 Directory of C:\Users\windowsuser\AppData\Local\lxss\rootfs\usr\bin

09/30/2016  09:08 AM           641,664 ssh
               1 File(s)        641,664 bytes
               0 Dir(s)  48,549,441,536 bytes free

But if that is installed, it is possible to call ssh from a Windows process

bash.exe -c "ssh vagrant@1.2.3.4 hostname"
@StefanScherer

This comment has been minimized.

Contributor

StefanScherer commented Sep 30, 2016

And rsync is also available after installing the subsystem.

@StefanScherer

This comment has been minimized.

Contributor

StefanScherer commented Sep 30, 2016

I wonder what would be possible to install Vagrant in the Linux subsystem. At least for remote (cloud) providers like aws, do, vcloud, ... it should work.

At least the installation works pretty well:

ubuntuuser@VAGRANT-10:/mnt/c/Users/windowsuser$ wget https://releases.hashicorp.com/vagrant/1.8.6/vagrant_1.8.6_x86_64.deb
--2016-09-30 09:27:14--  https://releases.hashicorp.com/vagrant/1.8.6/vagrant_1.8.6_x86_64.deb
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.60.69
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.60.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 76314834 (73M) [application/x-debian-package]
Saving to: 鈥榲agrant_1.8.6_x86_64.deb鈥

100%[==============================================================================>] 76,314,834  6.07MB/s   in 13s

2016-09-30 09:27:32 (5.78 MB/s) - 鈥榲agrant_1.8.6_x86_64.deb鈥 saved [76314834/76314834]

ubuntuuser@VAGRANT-10:/mnt/c/Users/windowsuser$ dpkg -i vagrant_1.8.6_x86_64.deb
dpkg: error: requested operation requires superuser privilege
ubuntuuser@VAGRANT-10:/mnt/c/Users/windowsuser$ sudo dpkg -i vagrant_1.8.6_x86_64.deb
sudo: unable to resolve host VAGRANT-10
[sudo] password for ubuntuuser:
Selecting previously unselected package vagrant.
(Reading database ... 25638 files and directories currently installed.)
Preparing to unpack vagrant_1.8.6_x86_64.deb ...
Unpacking vagrant (1:1.8.6) ...
Setting up vagrant (1:1.8.6) ...
ubuntuuser@VAGRANT-10:/mnt/c/Users/windowsuser$ vagrant --version
Vagrant 1.8.6

As I said, with Windows 10 crazy things are possible :-)

@thany

This comment has been minimized.

thany commented Oct 1, 2016

In Linux, you'd also need to check if all the required components are installed.

At any rate, not having ssh is only half an installation of vagrant. It's kind-of-required to work with a box, and requiring ssh to be installed is all fine and dandy. But, you're already allowing all kinds of ways to get ssh running on Windows - Ming, Cygwin, Git, PuTTY. Why not add WLS?

SSH in WLS is probably the most native and well-maintained SSH you're ever going to encounter on Windows. So if it's there, use it. If not - try the other options. There's no need to check for developer options, Bash installed or not, Ubuntu installed or not. Just check if the ssh executable exists, and if it does, use it.

@ricardowong

This comment has been minimized.

ricardowong commented Oct 1, 2016

@StefanScherer WSL is enabling windows to expand its flexibility by allowing us to have choice about what software to run independently of the OS. Like WINE does on Linux.

About running Vagrant on WSL it will nevever be possible since the scope of the project is to enable only User Level Apps, since virtualization requires thorough kernel access, it will never be available. The Microsoft team working on this has already commented on the limitations of WSL. Although, not as capable as virtualization, running linux software directly on windows is great. And for most purposes userspace is enough.

@ricardowong

This comment has been minimized.

ricardowong commented Oct 1, 2016

About running SSH on windows, the dev team is working on porting the whole Open SSH so it can run natively on windows. I think this will be a better choice in the future than running WSL > Bash > SSH or any of the current alternatives like Cygwyn, Putty.

See more on https://github.com/PowerShell/Win32-OpenSSH

@geerlingguy

This comment has been minimized.

Contributor

geerlingguy commented Oct 6, 2016

Note that I am able to install Vagrant in the WSL through apt or through the .deb packages, and run commands like vagrant box add, vagrant init, etc.鈥攂ut even if we fix the SSH pathing issue here, won't we be blocked by the fact that we can't run any providers inside the WSL?

When I try bringing up a box, I get "No usable default provider could be found for your system." (Even if VirtualBox is installed in Windows).

@hdave

This comment has been minimized.

hdave commented Nov 7, 2016

A big +1 for this issue. Currently I am using the ssh command installed under WSL. If Vagrant had the option to specify which ssh to use, I could just create a simple alias and be done with it.

@asvetliakov

This comment has been minimized.

asvetliakov commented Nov 12, 2016

Since latest versions of WSL allows to run native windows programs, i'd just to happy to use vagrant from WSL with windows providers (either virtualbox or hyperv).
This also would greatly improve chef/kitchen workflows.

@ryanerwin

This comment has been minimized.

ryanerwin commented Nov 23, 2016

Yes, completely agree with @hdave and @asvetliakov

WSL works quite well and microsoft is investing a lot in making it work better. With WSL working Ansible setups via Vagrant on Windows should finally work quite well, since Ansible can be run directly in WSL.
You can still hand off the actual virtualization to whichever hypervisor Windows is running (VMware in my case, Virtualbox for others).

This seems like a no brainer... Microsoft is making Windows 10 into a nice developer friendly environment, would be nice for Vagrant to be a part of that.

@morgajel

This comment has been minimized.

morgajel commented Dec 15, 2016

I'm currently trying to convince my colleagues to use a vagrant/ansible dev environment. It works great for the OSX users, but windows is a sore point since ansible doesn't play well natively on windows.

If Vagrant-on-windows could use the Ansible-on-linux-subsystem it would make me soooo happy.

@ricardowong

This comment has been minimized.

ricardowong commented Dec 16, 2016

@ryanerwin @morgajel
A workaround is to run vagrant on windows natively and then call Ansible playbooks from WSL bash.

You can't provision thorugh ansible directly yet, since ansible is not available on windows. And virtualbox is not able to run in WSL. I've managed to run virtualbox at WSL by adding it to the PATH thanks to the recent update that allows calling windows native executables from bash.

@geerlingguy

This comment has been minimized.

Contributor

geerlingguy commented Dec 16, 2016

the recent update that allows calling windows native executables from bash

@ricardowong - IIRC, that feature is only available to those in the Insider Preview program at this time, as it's not in the Anniversary Update. That said, is there a way to get that feature running on the non-insider build at this time?

@ricardowong

This comment has been minimized.

ricardowong commented Dec 16, 2016

@geerlingguy not that I know of sorry. It's available from build 14951
https://msdn.microsoft.com/en-us/commandline/wsl/release_notes#build-14951

There is this project that allows running windows native executables, it may be of your interest https://github.com/xilun/cbwin

@ryanerwin

This comment has been minimized.

ryanerwin commented Dec 18, 2016

@geerlingguy the anniversary release of Windows 10 already includes WSL, and big WSL improvements will be available in the two Windows 10 releases that come out in 2017. Personally I'm a sysadmin that's been using a Mac since 2000, and am very happy with WSL as a development environment, already more convenient than Darwin in many ways though not yet feature complete - MSFT is improving it very quickly.

@krzysztofantczak

This comment has been minimized.

krzysztofantczak commented Dec 28, 2016

@ricardowong no need for cbwin since few releases now. vagrant.exe can be issued directly from under WSL.

@geerlingguy

This comment has been minimized.

Contributor

geerlingguy commented Dec 28, 2016

@krzysztofantczak - So far the integration that allows calling out to the windows environment from WSL is only in the Insider Preview program, it seems... meaning most users can't rely on it yet (until the next major public Windows 10 update)鈥攁nd I can't point my project's users to that as a solution yet.

Once it's publicly available, it will be awesome :)

@krzysztofantczak

This comment has been minimized.

krzysztofantczak commented Dec 28, 2016

@geerlingguy latest version of WSL is far more stable and feature complete then the one published with anniversary update. I wouldn't recommend any user to use this version TBH. But of course i understand many people have many different needs ;)

@ricardowong

This comment has been minimized.

ricardowong commented Dec 29, 2016

@krzysztofantczak

Although right now i'm on the latest build, I've had trouble once when the microsoft team was forcing users to update to the latest version or the system would become unusable. I would have updated but Windows Update was broken so I was stuck with an older build and microsoft would randomly shut down the computer ( as an antipiracy measure, ironically as insider it wouldn't detect my own W10 valid license saved on my microsoft account ).

Since the newest build was not provided for manual download, I had to spend hours editing registry keys until I managed to get windows detect the newer build. So... I love being on the latest build, but Anniversary Update should be the only place anything you work on. I'm looking forward to step down the slow ring as soon as possible.

About running vagrant, it can't run natively on WSL since virtualbox can't be installed, you can reference the windows executable but then you can't run ansible. You can install vagrant on WSL and have it call window's virtualbox, here's a small guide:
Microsoft/WSL#733 (comment)

@krzysztofantczak

This comment has been minimized.

krzysztofantczak commented Dec 29, 2016

@ricardowong like i said, different people, expect different things. Also, "but Anniversary Update should be the only place anything you work on", no. Like i said, it is too far behind. Perhaps its enough for people looking for linux'a'like experience ;) But when You find out, that pretty much anything related to networking is pure nightmare i think You will understand ;) Btw. latest build still lacks of stability in this regard but its far more usable. As for Your update problems, well... One thing i learned over the years watching people using windows (i'm not windows fan, i'm just stucked with it atm.), it works like russian roulette - personally i didn't encounter anything You described while updating.

Also, when running things under WSL You just can't use the same mindset as on linux. It's not fully working operating system. And i didn't said anything about running vagrant natively :)

Nice trick to cheat vagrant with symlink thought....

@leighmcculloch

This comment has been minimized.

leighmcculloch commented Jan 7, 2017

I'm solving this problem by using a simple six line .bat file to wrap ssh commands in a call to bash.exe -c.

Grab ssh.bat file from https://github.com/leighmcculloch/windows-10-bash-aliases and stick it anywhere in your system PATH and vagrant ssh will work.

@kirugan

This comment has been minimized.

kirugan commented Feb 4, 2017

@leighmcculloch this solution is ok except that it still requires password during ssh connect :(

@leighmcculloch

This comment has been minimized.

leighmcculloch commented Feb 4, 2017

Yeah unfortunately this is because the SSH agent isn't running. This could be resolved by running the SSH agent in the bat and adding keys. I could add that.

@kirugan

This comment has been minimized.

kirugan commented Feb 4, 2017

@leighmcculloch it will be 100% workable solution then, thanks!

@thany

This comment has been minimized.

thany commented Feb 4, 2017

I don't feel this issue is drawing towards a solution. As it stands, vagrant requires ssh to be installed magically. It doesn't include it, it doesn't look for and use ssh from WLS. It requires the user to install a crappy half-arsed implementation like cygwin, mingw, or whatever some other Linux-based tools on Windows come with.

I thought using WLS was a great solution, because it's so much closer to what the folks behind Vagrant seem to love so much. But I'm tasting a bit of unwillingness together with confusion and perhaps a hint of false assumptions.

The real problem is simple:
Install Vagrant, try running vagrant ssh and it WILL error, ALWAYS. Because there is no ssh. Where you're going to pull an ssh executable from, I suspect most users couldn't care less. As long as it works.

@leighmcculloch

This comment has been minimized.

leighmcculloch commented Feb 4, 2017

@kirugan: It's updated and will use the SSH agent.

It requires the user to install a...implementation

@thany: I agree it'd be great if it automatic, and I'd prefer it to be. But using WSL is still pulling in something that isn't there by default. WSL has to be manually enabled and then the first time you run bash it has to setup Ubuntu. This whole process is as difficult as any other ssh installation and comes with it's own mix of issues since a new shell is being started the SSH-agent has to be setup, keys added for forwarding, etc.

@thany

This comment has been minimized.

thany commented Feb 4, 2017

WSL is a first-party component that'll be the same for everyone, and it's closest to the real thing.

@kirugan

This comment has been minimized.

kirugan commented Feb 4, 2017

@leighmcculloch unfortunately now it's not working, i think cause one of arguments is
-i E:/vm/ubuntu/.vagrant/machines/default/virtualbox/private_key
but inside wsl there is no such path (there is only /mntr/e/vm/ubuntu/...)
`

@geerlingguy

This comment has been minimized.

Contributor

geerlingguy commented Apr 10, 2017

I've been tooling around with hack after hack to see if I can get vagrant.exe commands to work well within WSL/Ubuntu Bash (using @leighmcculloch's .bat file, using tips from here and Microsoft/WSL#733, and testing out different approaches), but it seems that there still isn't a simple way to use Vagrant and get vagrant ssh et all working using WSL.

I think it may be in Vagrant's best interest to get things working somehow between Windows/WSL鈥攖he Creator's edition update (which allows calling out to Windows executables) drops this week, and it will be the first time there's a first party solution (much nicer than Cmder, Cygwin, Git Bash, etc.) to the whole "how do you ssh from Windows" problem.

For myself, there are currently two blockers that keep me using Cmder:

  • I can't vagrant ssh easily鈥擨 have to run vagrant.exe ssh-config then use the values to run ssh -p [port] vagrant@127.0.0.1 manually.
  • I can't get environment variables from the Ubuntu environment passed to vagrant.exe (this isn't a hard blocker for me, but would be so nice to have).

Note that you can run vagrant.exe up|halt|suspend|destroy and vagrant.exe provision, as long as you're working with code/config that's somewhere in the Windows filesystem (e.g. /mnt/c/anything_in_here). But they don't respect environment variables, and one of the most important commands, ssh, doesn't work yet (even using the .bat file @leighmcculloch mentioned earlier).

@geerlingguy

This comment has been minimized.

Contributor

geerlingguy commented Apr 10, 2017

Also, my best instructions currently for using only Ubuntu Bash (no Cmder, cygwin, Git Bash, etc. required) to work with Vagrant are here: geerlingguy/drupal-vm#1012 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment