Vagrant: WSL SSH key error when not running in user directory or WSL filesystem

Created on 30 Jun 2017  ยท  6Comments  ยท  Source: hashicorp/vagrant

Vagrant version

```$ vagrant -v
Vagrant 1.9.6

### Host operating system
Microsoft Windows 10 Pro Version    10.0.15063 Build 15063, running vagrant from the WSL

### Guest operating system
centos/7 base box

### Vagrantfile
```ruby
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
end

Debug output

https://gist.github.com/robwiss/9642b52c8f108082c34de94645f26448

Expected behavior

Vagrant should remove the insecure private key and insert the new private key.

Actual behavior

Vagrant fails to insert the new private key if the directory containing the Vagrantfile is not located in the WSL filesystem or the Windows user's home directory.

Error is as follows:

The private key to connect to the machine via SSH must be owned
by the user running Vagrant. This is a strict requirement from
SSH itself. Please fix the following key to be owned by the user
running Vagrant:

/mnt/c/temp/.vagrant/machines/default/virtualbox/private_key

See the debug output for full error info.

Steps to reproduce

  1. Make a directory under /mnt/c from within the WSL (or make it in Windows)
  2. Add a Vagrantfile
  3. Run vagrant up
WSL documentation hoswindows

Most helpful comment

Vagrant will ignore file permission checks when the path is within the path set in the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH. This is set as the user's home directory on the Windows system by default but can be overridden to a custom location. @robwiss, for you this would look like:

export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/temp"

The relevant env var documentation is located here: https://www.vagrantup.com/docs/other/wsl.html#vagrant_wsl_windows_access_user_home_path The details of the impact each of those env vars still needs to be added, and this ticket will be closed once they have been included.

All 6 comments

Temporary solution could be to create a wrapper that issues the following:

#!/bin/bash
sudo -e PATH="${PATH}" vagrant $@

(as WSL translates user to root) but there is still file permission problem (should be 0600).

A workaround is to create symlink:

mv .vagrant ~/.project-vagrant
ln -sv ~/.project-vagrant .vagrant

Vagrant will ignore file permission checks when the path is within the path set in the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH. This is set as the user's home directory on the Windows system by default but can be overridden to a custom location. @robwiss, for you this would look like:

export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/temp"

The relevant env var documentation is located here: https://www.vagrantup.com/docs/other/wsl.html#vagrant_wsl_windows_access_user_home_path The details of the impact each of those env vars still needs to be added, and this ticket will be closed once they have been included.

@chrisroberts thank you

@chrisroberts thanks for that, solved my problem. Do you know if I can add this env var to a config file or something, so I don't need to run it every morning after I log in?

@dthunder746 You could put it in ~/.bash-profile, ~/.profile or, preferrably not, in ~/.bashrc

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings