How to authenticate to a VM using Vagrant up?
The issue was caused because no Public key reside on the Vagrant box. One of the following two options solves the issue.
The first option is to create a new Vagrant box using Packer. Add the following snippet to the json file and build the Vagrant box.
"provisioners": [{
"type": "shell",
"scripts": [
"scripts/vagrant.sh"
]
}]
The content of this vagrant script is as follows:
#!/bin/bash
yum install wget -y
mkdir /home/vagrant/.ssh
wget --no-check-certificate \
'https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub' \
-O /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
chmod -R go-rwsx /home/vagrant/.ssh
The second option is to repackage (vagrant package
) the Vagrant box once the following commands specified here have been run:
mkdir -p /home/vagrant/.ssh
wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
chmod 0700 /home/vagrant/.ssh
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
First, try: to see what vagrant private key in you machine config
$ vagrant ssh-config
Example:
$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/konst/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
http://docs.vagrantup.com/v2/cli/ssh_config.html
Second, do: Change content of file insecure_private_key with content of your own system private key