Chris
Chris

Reputation: 486

vagrant provision ssh issue

I have vagrant running scotchbox. I recently tried to add id_rsa.pub to /vagrant/home/.ssh hoping to be able to ssh in without entering password. Once I did that it acted the same so I removed it. Now I was adding another site to the configuration and now I can't do vagrant provision as it gives me the following error.

SSH authentication failed! This is typically caused by the public/private keypair for the SSH user not being properly set on the guest VM. Please verify that the guest VM is setup with the proper public key, and that the private key path for Vagrant is setup properly as well.

Here is what I get from vagrant ssh-config

HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "/Users/username/.vagrant.d/boxes/scotch-VAGRANTSLASH-box/3.0/virtualbox/vagrant_private_key"
  IdentitiesOnly yes
  LogLevel FATAL

Here is my vagrant file.

Vagrant.configure("2") do |config|

    config.vm.box = "scotch/box"
    config.vm.network "private_network", ip: "192.168.10.10"
    config.vm.hostname = "scotchbox"
    config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=775", "fmode=664"]


config.vm.provider "virtualbox" do |v|
        v.memory = 2048
        v.cpus = 2
    end

    # Optional NFS. Make sure to remove other synced_folder line too
    #config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }


    config.vm.provision "shell", inline: <<-SHELL

            ## Only thing you probably really care about is right here
            DOMAINS=("site1.dev" "site2.dev" "site3.dev" "site4.dev" "site5.dev" "ai.d$

            ## Loop through all sites
            for ((i=0; i < ${#DOMAINS[@]}; i++)); do

                ## Current Domain
                DOMAIN=${DOMAINS[$i]}

                echo "Creating directory for $DOMAIN..."
                mkdir -p /var/www/$DOMAIN/public

                echo "Creating vhost config for $DOMAIN..."
                sudo cp /etc/apache2/sites-available/scotchbox.local.conf /etc/apache2/si$

                echo "Updating vhost config for $DOMAIN..."
                sudo sed -i s,scotchbox.local,$DOMAIN,g /etc/apache2/sites-available/$DOM$
sudo sed -i s,/var/www/public,/var/www/$DOMAIN/public,g /etc/apache2/site$

                echo "Enabling $DOMAIN. Will probably tell you to restart Apache..."
                sudo a2ensite $DOMAIN.conf

            done

        SHELL
end

I also get authentication error when doing vagrant up until it times out but box still starts and works and I can ssh into it with password.

I have looked through numerous other questions and have tried some things but nothing seemed to fix it. Ideally I want to ssh in using keys but would settle just to get back so I can provision it and have to login with password.

Thanks

Upvotes: 2

Views: 3736

Answers (1)

Chris
Chris

Reputation: 486

I figured this out by setting the following in my Vagrantfile to use ssh key that vagrant created when it initialized.

config.ssh.private_key_path = "/pathtovagrantfolder/.vagrant/machines/default/virtualbox/private_key"

Upvotes: 1

Related Questions