Sometimes when you package VirtualBox VM to get vagrant box, you get message "Warning: Authentication failure. Retrying... " while trying to start vagrant machine. Check
Step by step guide on using existing virtual machines with Vagrant
I tried to use vagrant ssh-config to generate private key for vagrant, then add it to Vagrantfile but it didn't work out for me.The key on .vagrant/machines/default/virtualbox/private_key won't authenticate and login successfully.
The error message is shown below:
The error message is shown below:
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
If you have encountered same problem,this solution may help you.default: Adapter 1: nat==> default: Forwarding ports...
default: Adapter 2: bridgeddefault: 22 => 2222 (adapter 1)==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Error: Connection timeout. Retrying...
default: Error: Connection timeout. Retrying...
default: Error: Connection timeout. Retrying...
default: Error: Connection timeout. Retrying...
default: Error: Authentication failure. Retrying...
default: Error: Authentication failure. Retrying...
default: Error: Authentication failure. Retrying...
default: Error: Authentication failure. Retrying...
default: Error: Authentication failure. Retrying...
Prerequisites:
- Installed vagrant
- Vagrant Instance already added to VirtualBox,Vmware or any other provider you use.
- SSH on Vagrant instance set to start on boot up
My vagrant appliance working directory is : ~/vagrant/centos-asterisk-server. This is the same directory that i will put my private and public keys
mkdir -p ~/vagrant/centos-asterisk-server/.sshGenerate private/private rsa key pair with ssh-keygen
ssh-keygenI will use following settings:
Enter file in which to save the key : /home/josepy/vagrant/centos-asterisk-server/.ssh/id_rsa
Enter passphrase (empty for no passphrase): <Press Enter/Return key>
Enter same passphrase again: <Press Enter/Return key>
It will successfully generate RSA 2048 keys. Remember i didn;t set passphrase ( just pressed enter key)
Step 2: Edit Vagrantfile and specify location of generated private key
vi ~/vagrant/centos-asterisk-server/VagrantfileWe'll add it just below config.vm.box = "" line.We'll also set "config.ssh.forward_agent" to True.
config.ssh.private_key_path = "/home/josepy/vagrant/centos-asterisk-server/.ssh/id_rsa"My username and password that vagrant we'll login in with are the default:
config.ssh.forward_agent = true
username: vagrant
password: vagrant
If you have different username and password, specify them on Vagrantfile
vi VagrantfileAdd:
config.ssh.username = 'username'Save the changes and quit.
config.ssh.password = 'password'
Step 3: Copy rsa public key to vagrant instance. We'll start the Virtual Machine with VirtualBox directly.
Make sure ssh is running and port forwarding is configured. Follow steps below
- Open Oracle VirtualBox ( GUI)
- Right click on the name of Virtual Machine and go to settings > Network > Adapter 1 ( NAT) > Port Forwarding
Name : ssh
Protocol: TCP
Host ip: 127.0.0.1
Host Port: 2200
Guest port: 22
- Copy rsa public key to Virtual Machine
ssh-copy-id -f -i /home/josepy/vagrant/centos-asterisk-server/.ssh/id_rsa.pub -p 2200 vagrant@127.0.0.1

- Stop Virtual Machine ( power off) and start it with vagrant
cd /home/josepy/vagrant/centos-asterisk-server/
vagrant up
You can confirm that key was copied to guest os. Do
vi $HOME/.ssh/authorized_keysNow start Vagrant instance using vagrant up command. It should start without any error,



