When setting up a vagrant test kitchen, it looks like by default authentication is done via password. I would like to do it using a keypair.
I added the driver_config and ssh_key lines to my .kitchen.yml:
and finally a timeout. Although the VM is still accessible via password authentication.
So it looks like my modification to .kitchen.yml tells chef to try and connect to the box using that key pair, but it does not tell the box to have the corresponding public key in ~vagrant/.ssh/authorized_keys. What do I need to do to get this to work? And where is it documented (I couldn’t find it).
Also, in the ‘ssh_key’ line I hardcoded the path to my private key, but for other developers it will be different. Is there a way to avoid this hardcoding?
Adding a little more information. If I take the lines I added out of kitchen.yml and then destroy and recreate my kitchen, I see the following output:
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
I assume that the insecure key it’s referring to is the one in ~/.vagrant.d/insecure_private_key, and indeed I cannot ssh using that key.
So where is the newly generated keypair that it’s talking about? If I can find the private key from that key pair, I’d be in business.