Vagrant WSL rsync and ssh permission error

3.1k views Asked by At

I have a really strange problem, well although its self-explaining, I keep having permission problems when using rsync and vagrant ssh in WSL.

I have vagrant version 1.9.8 installed in Windows as well as in WSL. I exported the following environment variables:

export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/Vagrant"

When I run vagrant up it succesfully creates a VM in virtualbox. But halfway I get the following error:

==> salt: Rsyncing folder: /mnt/c/Vagrant/ => /vagrant
There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.

Host path: /mnt/c/Vagrant/
Guest path: /vagrant
Command: "rsync" "--verbose" "--archive" "--delete" "-z" "--copy-links" "--no-owner" "--no-group" "--rsync-path" "sudo rsync" "-e" "ssh -p 2222 -o LogLevel=FATAL  -o ControlMaster=auto -o ControlPath=/tmp/ssh.216 -o ControlPersist=10m  -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i 
'/mnt/c/Vagrant/.vagrant.d/insecure_private_key'" "--exclude" ".vagrant/" 
"/mnt/c/Vagrant/" "[email protected]:/vagrant"
Error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

When I use vagrant ssh salt I get the error:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

It doesn't matter what kind of Vagrantfile I use. When I place the Vagrantfile in /root of the WSL, I can use vagrant ssh, but I still get the error of rsync.

This is really strange because the WSL documentation of Vagrant is saying the following:

Other useful WSL related environment variables:

VAGRANT_WSL_WINDOWS_ACCESS_USER - Override current Windows username
VAGRANT_WSL_DISABLE_VAGRANT_HOME - Do not modify the VAGRANT_HOME variable
VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH - Custom Windows system home path

If a Vagrant project directory is not within the user's home directory on the Windows system, certain actions that include permission checks may fail (like vagrant ssh). 
When accessing Vagrant projects outside the WSL Vagrant will skip these permission checks when the project path is within the path defined in the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH environment variable. 
For example, if a user wants to run a Vagrant project from the WSL that is located at C:\TestDir\vagrant-project:

Does anyone know how to solve this problem? Or has anyone experienced this problem himself? I hope someone can help me out.

1

There are 1 answers

2
Haije Ploeg On BEST ANSWER

For the people who are interested in this, here is the solution (at least the solution for me).

I deleted the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/Vagrant" environment variable. I noticed that the VAGRANT_HOME environment variable is not set. When you set this to the default location (~/.vagrant.d) it can work and manipulate file permissions, something you can't do with Windows files.

So use this:

$ export VAGRANT_HOME="/home/<user>/.vagrant.d"

After changing this key the rsync problem was gone, but the ssh permission error was still there. This is because Vagrant is inserting a new ssh key by default and places this in the .vagrant folder in the root directory of the Vagrantfile. So make sure you are putting this in your Vagrantfile:

config.ssh.insert_key = false

The main cause of this problem is that Vagrant does a permission check on the ssh keys. Since Vagrant will put the new generated ssh key in the same folder as the Vagrantfile, it will fail due permission checks. The permission check will fail on a Windows path. By setting the config.ssh.insert_key = false it will keep the default insecure key, which is located in the VAGRANT_HOME folder.

I also experienced problems with the config file in the .ssh folder. For my git ssh configuration I used the RSAAuthentication yes option. Therefor rsync can fail also.

I hope this will help somebody who is struggling with WSL as well. I now have a fully working Vagrant setup in WSL on Windows.