vagrant
vagrant copied to clipboard
Cannot SSH from WSL to VM, although it's SSH is possible from host outside WSL.
Vagrant version
Vagrant 2.2.14
Host operating system
Windows 10 Education Version 10.0.19041 Running WSL2
Guest operating system
Ubuntu Bionic
Vagrantfile
Default file from vagrant init hashicorp/bionic64
(Comments Removed)
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/bionic64"
end
Debug output
https://gist.github.com/Fowlron/35838ae9d801e2a6713ce392a821cedf
Expected behavior
vagrant up
and vagrant ssh
should be able to properly connect to the running VM.
Actual behavior
Although the VM is starting and running properly, I cannot SSH from WSL into the VM. Note that SSH is possible from the windows host, as ssh [email protected] -p 2222
on powershell will successfully connect to the running VM created by vagrant.
Steps to reproduce
Starting on an empty directory (/mnt/d/vagrant/vagrantexample
)
-
vagrant init hashicorp/bionic64
-
vagrant up
Note also that my env includes VAGRANT_WSL_ENABLE_WINDOWS_ACCESS=1
and VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH=/mnt/d/vagrant
.
This seems to be exactly the same issue as in https://github.com/hashicorp/vagrant/issues/11716. I am also facing the same issue
Hi there,
Faced the issue too.
If I may suggest a change. The following would be a fix:
- the second port forwarding entry is created on 0.0.0.0 that allows to ssh to VirtualBox VM from WSL2 on Windows IP.
- Windows IP is automatically selected for vagrant ssh command instead of localhost.
Pretty much what I have in my workaround: https://github.com/Karandash8/virtualbox_WSL2. If that makes sense I can polish it a bit and open a PR.
Hello @Karandash8 ,
I will give it a go and let you know how it goes. Cheers and thanks for your work.
Hello @Karandash8 ,
I have been testing your plugin and it's working fine, thank you so much for all that work and for doing that.
Just a qq that you may know how to fix it, vagrant ssh asks for password, I believe that is more an issue re. vagrant keys being setup on /mnt/nc and it's permissions, do you have any way of wor around that?
Cheers,
Hey @nmofonseca,
Glad it worked for you!
Strange, I don't have any problem with ssh keys, it just works. I have nothing special in my vagrantfile, just:
config.vm.synced_folder '.', '/vagrant', disabled: true
and I keep my vagrantfile on WSL filesystem not on Windows one.
@nmofonseca I experience the same issue as you - when running vagrant ssh
the process hangs for a second or two and then prompts for a password.
I did find, that once I've disabled the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH export in my .bashrc - I was able to run a new machine on my env. and run vagrant ssh
successfully using the Vagrant private key.
I've tried to copy the "insecure_private_key" file to my specific VAGRANT home path - but Windows WSL got wired permissions. I did try to play with it for a bit - no luck yet.
Hey @nmofonseca,
Glad it worked for you!
Strange, I don't have any problem with ssh keys, it just works. I have nothing special in my vagrantfile, just:
config.vm.synced_folder '.', '/vagrant', disabled: true
and I keep my vagrantfile on WSL filesystem not on Windows one.
Apologies for the delay and taking so long to reply, wow! since March ridiculous.
I haven't used it for a while, to be honest, but I also kept my Vagrant File in WSL but I do sync using NFS my local folder with the Vagrant machine.
The vagrant ssh not working for me is not a blocker issue because I use Ansible on provision to install my own keys so I can ssh anyway in the end and run and test my ansible playbooks against the Vagrant machines, that was my main use case for Vagrant.
Once again @Karandash8 thank you so much for the work you did and for providing this plugin.
@nmofonseca I experience the same issue as you - when running
vagrant ssh
the process hangs for a second or two and then prompts for a password. I did find, that once I've disabled the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH export in my .bashrc - I was able to run a new machine on my env. and runvagrant ssh
successfully using the Vagrant private key.I've tried to copy the "insecure_private_key" file to my specific VAGRANT home path - but Windows WSL got wired permissions. I did try to play with it for a bit - no luck yet.
I didn't spend much time on it either @Devorkin , I work around it by installing my own ssh keys using Ansible, but I never tried the option you mentioned, if I can I will give it a try also.
@nmofonseca I experience the same issue as you - when running
vagrant ssh
the process hangs for a second or two and then prompts for a password. I did find, that once I've disabled the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH export in my .bashrc - I was able to run a new machine on my env. and runvagrant ssh
successfully using the Vagrant private key. I've tried to copy the "insecure_private_key" file to my specific VAGRANT home path - but Windows WSL got wired permissions. I did try to play with it for a bit - no luck yet.I didn't spend much time on it either @Devorkin , I work around it by installing my own ssh keys using Ansible, but I never tried the option you mentioned, if I can I will give it a try also.
The problem with access rights to mounted directory has been resolved this way:
sudo bash -c 'cat << EOF >> /etc/wsl.conf
[automount]
enabled=true
options=metadata,uid=1000,gid=1000,umask=022
EOF'
After this, VAGRANT_HOME can be moved. But then vagrant can only be run from under WSL, otherwise access rights problems will appear Windows.
After hours of issues. I found a solution for me. Keeping it here for future reference.
Most tutorials tells us to use a vagrantfile which binds the port 22 to 2222 of the 127.0.0.1, which causes issues with the firewall and so on. When I removed the restriction to the host ip (keeping it empty), it instantly got connected for me.
Another solution is to use something like tailscale/zerotier instead of localhost. Which also worked great so far.