Monday, 2 March 2020

[SOLUTION] Vagrant box authentication failure after packaging box

 Bringing machine 'default' up with 'virtualbox' provider...  
   ==> default: Clearing any previously set forwarded ports...  
   ==> default: Clearing any previously set network interfaces...  
   ==> default: Preparing network interfaces based on configuration...  
     default: Adapter 1: nat  
     default: Adapter 2: hostonly  
   ==> default: Forwarding ports...  
     default: 22 => 2222 (adapter 1)  
   ==> default: Running 'pre-boot' VM customizations...  
   ==> 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: Warning: Connection timeout. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  
     default: Warning: Authentication failure. Retrying...  

SOLUTION

1. Press CTRL + Z to break the 'default: Warning: Authentication failure. Retrying... or wait for few more minutes

2. Login into your guest machine - vagrant ssh , which should prompt you for password, vagrant , the default password for vagrant

3. Then go to - /home/vagrant/.ssh  and remote all the contents inside it, if the path not existed create the directory - mkdir -p /home/vagrant/.ssh

4. Then run following commands

 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  

5. Exit from the gust machine and restart it ( vagrant reload)

6. Voila! Problem solved. You should be good to go.

SUPPRESS THE  ERRORS BY ADDING FOLLOWING LINES IN VAGRANT FILE

   
 Vagrant.configure("2") do |config|  
      config.vm.box = "package.box"  
      config.vm.network "private_network", ip: "192.168.33.10"  
      config.vm.hostname = "development.vm"  
      config.vm.network "forwarded_port", guest: 80, host: 8080  
      config.vm.network "forwarded_port", guest: 3000, host: 3000  
     
      config.vm.synced_folder ".", "/var/folder_name", :mount_options => ["dmode=777", "fmode=666"]  
             
      config.ssh.username = "vagrant"  
      config.ssh.password = "vagrant"  
        
      config.ssh.insert_key = false  
             
      config.vm.provider "virtualbox" do |v|  
      v.memory = 4024  
      v.cpus = 1  
   end  
 end