theUnknown777
theUnknown777

Reputation: 581

vagrant ssh doesn't work as expected, it doesn't honor my custom settings

First of all, i set up a separate ssh key for my vagrant box. And i have this setup on my ~/.ssh/config

Host    vag_ubuntu14
HostName 127.0.0.1
Port    2222
User    vagrant
IdentityFile ~/.ssh/vag_ubuntu14/id_rsa

And i copied the public key to the vagrant box's ~/.ssh/authorized_keys with this command.

cat ~/.ssh/vag_ubuntu14/id_rsa.pub | ssh -p2222 [email protected] 'cat > ~/.ssh/authorized_keys'

So when running ssh vag_ubuntu14 works as expected. But running vagrant ssh to ssh to the vagrant box doesn't work. It produces authentication failure.

Here's my current Vagrant file with the path to the private key already specified.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu14_04"

  config.vm.provider "virtualbox" do |vb|
    vb.name = "Ubuntu 14.04"
  end

  config.vm.provision :shell, path: "provision/bootstrap.sh"

  config.ssh.private_key_path = '/home/chris/.ssh/vag_ubuntu14/id_rsa'

end

But when i run vagrant ssh-config, it doesn't respect the custom path to the private key that i specified on my Vagrantfile.

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/chris/ubuntu14_04/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

Upvotes: 4

Views: 6031

Answers (2)

ajay_full_stack
ajay_full_stack

Reputation: 554

What worked for me! (may be its patch or Jugad)

In VagrantFile

   config.ssh.private_key_path = 'FULL PATH OF PRIVATE KEY'

eg.

  config.ssh.privae_key_path = 'C:/Users/ajs_n/.ssh/private_key'

Care: path separators subject to OS.

Upvotes: 0

theUnknown777
theUnknown777

Reputation: 581

For anyone who got the same problem. I've found that the solution is very simple.

For your custom configuration of the location of the private key on your Vagrantfile to be honored. You must first delete the default private key.

You can see the location of the private key by running:

`vagrant ssh-config`

Delete the private key as specified on the IdentityFile.

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/chris/ubuntu14_04/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

When you've deleted the private key that comes pre-installed on your vagrant box, then just specify the location of your new private key on Vagrantfile.

config.ssh.private_key_path = 'location of your private key'

To check that your new private key is the one that is read, then run vagrant ssh-config again.

Upvotes: 7

Related Questions