Why am I packaging a private key?

33 views
Skip to first unread message

boldlookup

unread,
Sep 4, 2019, 1:15:18 AM9/4/19
to Vagrant
Hi,
I am trying to package a LXC box. This LXC box I created using Vagrantfile similar to snippet below.

Before I run vagrant package I put the Vagrant public key authorized_keys. This is a required step is my understanding after having packaged a few VirtualBox boxes.

For this LXC box I end up with a box file which includes a private_key file. After I import the box the key is
/home/<username>/.vagrant.d/boxes/c2-VAGRANTSLASH-ubuntu1804/0.1.0/lxc/vagrant_private_key

Subsequently Vagrant fails to SSH into the box because the authorized_keys only contains the Vagrant public key that I put there.

Where does this private_key come from? How do I prevent it from being packaged into the box?

Vagrant.configure(2) do |config|
  config
.vm.define 'ubuntu1804' do |cfg|
    cfg
.vm.box = 'emptybox/ubuntu-bionic-amd64-lxc'
    cfg
.vm.provider :lxc do |lxc|
      lxc
.container_name = :machine
   
end
    cfg
.vm.provision 'chef_zero' do |chef|

     
...

   
end
 
end
end


boldlookup

unread,
Sep 6, 2019, 2:53:34 AM9/6/19
to Vagrant
As a workaround for now I changed my Vagrantfile to not replace the insecure key

cfg.ssh.insert_key = false # don't replace insecure key


Dennis Chang

unread,
Sep 9, 2019, 7:39:45 PM9/9/19
to Vagrant
Use the "vagrant ssh-config" within your project directory to see where the private key is located for your specific project.
If you don't replace the insecure private key, then that standard key located at ~/.vagrant.d/insecure_private_key is used.
If you do replace the insecure private key then "vagrant ssh-config" will tell you where the private key is located.

And to test your private key,

ssh -p 2222 -i ~/whereever/private/key/is/located vag...@127.0.0.1

And you should be able to login.

This should work the same way "vagrant ssh" works.

Hope that helps.
Reply all
Reply to author
Forward
0 new messages