How to fix Vagrant error: `private_key_path` file must exist:
Asked Answered
P

7

6

I've been using PuPHPet to create virtual development environments.

Yesterday I generated a config file for a new box. When I try to spin it up using the vagrant up command, I get the following error message:

C:\xx>vagrant up

Bringing machine 'default' up with 'virtualbox' provider... There are errors in the configuration of this machine. Please fix the following errors and try again:

SSH: * private_key_path file must exist: P://.vagrant.d/insecure_private_key

I came across this question and moved the insecure_private_key from puphpet\files\dot\ssh to the same directory as where the Vagrantfile is. However this gives the same error.

I'm also confused by the directory given in the error message;

P://.vagrant.d/insecure_private_key

Why is the 'P' drive mentioned?

My Vagrantfile can be found here.

Appreciate any advice on solving this error.

Pantalets answered 16/4, 2015 at 11:16 Comment(2)
Can you share your Vagrantfile?Bemock
Updated in question.Pantalets
P
7

I fixed the problem by replacing the path to insecure_private_key by hard coding the path to the insecure_private_key file.

So it went from:

config.ssh.private_key_path = [
    customKey,
    "#{ENV['HOME']}/.vagrant.d/insecure_private_key"
]

To:

config.ssh.private_key_path = [
    customKey,
    "C:/Users/My.User/.vagrant.d/insecure_private_key"
]
Pantalets answered 4/6, 2015 at 14:45 Comment(0)
W
6

It looks like it's because you may have performed a vagrant destroy which deleted the insecure_private_key.

But the vagrant file looks up the puphpet\files\dot\ssh files, if they are there, it looks for the insecure_private_key.

delete (rename) the id_rsa files in puphpet\files\dot\ssh

this fixed it for me!

Woodpile answered 5/5, 2015 at 11:11 Comment(1)
delete (rename) the id_rsa files in puphpet\files\dot\ssh worked for me!Karsten
R
3

When you are sharing your puphet configuration to your teammates, hardcoding the private_key_path is not advisable as per the accepted answer.

My host computer is windows so i have added a new environment variable VAGRANT_HOME with value %USERPROFILE% since this is where my /.vagrant.d folder resides. When you add this variable just make sure that you close command prompts that are open so the variable will be applied

Hope this helps

Roeser answered 11/3, 2016 at 11:30 Comment(0)
B
2

You can also just delete all the files in the puphpet folder rm -rf puphpet/files/dot/ssh/* and the vm should regenerate them when you run vagrant provision.

Behest answered 19/12, 2015 at 21:0 Comment(0)
M
1

I'm not sure what's wrong with your Vagrant installation, but this line:

vagrant_home = (ENV['VAGRANT_HOME'].to_s.split.join.length > 0) ? ENV['VAGRANT_HOME'] : "#{ENV['HOME']}/.vagrant.d"

is what sets up the variable that is later on used here:

config.ssh.private_key_path = [
  customKey,
  "#{vagrant_home}/insecure_private_key"
]

The reason this is happening is that as of Vagrant 1.7, it generates a unique private key for each VM you have. There's, what I consider to be, a bug in that Vagrant completely ignores user-defined private_key_path if it detects that it generated a unique key previously.

What PuPHPet is doing here is letting Vagrant generate its unique SSH key, then once the VM boots up and has SSH access, it goes in and generates another key to replace it.

The reason we're replacing it is because this new Vagrant feature only works on OSX/Linux hosts, due to Windows not having the required tools.

My way works across all OS because it does the SSH key generation within the VM itself.

All this is semi-related to your question, but the answer is that something's wrong with your Vagrant installation if those environment variables have not been defined.

Moorland answered 16/4, 2015 at 22:46 Comment(1)
Thanks for the info. I did upgrade my version of Vagrant but to no avail.Pantalets
X
0

Adding to PunctuationMark's answer you can also set the VAGRANT_HOME environment variable in your Vagrantfile: ENV['VAGRANT_HOME'] = ENV['USERPROFILE']

Xeres answered 2/5, 2017 at 18:16 Comment(0)
G
0

Editing this following line in Vagrantfile worked for me.

PRIVATE_KEY_SOURCE      = '~/.vagrant.d/insecure_private_key'
Giovanna answered 29/11, 2018 at 6:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.