Ubuntu – How to change the ssh auth method in vagrant, from password to private key

private-keysshUbuntuvagrant

I run vagrant(1.7.2) on Mac OS(10.10.3) with Snappy Ubuntu Core(15.04 stable), for docker, using VirtualBox 4.3.28 as a provider.

I can manually ssh in the Ubuntu guest OS by a private key method in Mac terminal.

But the "vagrant ssh" command sticks to the password method, and I cannot figure out how to change the auth method.

vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/ubuntu-15.04-snappy-core-stable' is up to date...
==> 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: bridged
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 192.168.0.13:2222
default: SSH username: ubuntu
default: SSH auth method: password
default: Warning: Connection refused. Retrying...
default: Warning: Connection refused. Retrying...

I have read through the vagrant doc about ssh settings, but found nothing "auth method" related.

And my "vagrant ssh-config" result:

vagrant ssh-config

Host default
HostName 192.168.0.13
User ubuntu
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile  /Users/brady/spa/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

It shows that the password authentication is disabled, but seems like it did not work in "vagrant up"/"vagrant ssh".

And the access permission to the vagrant private key file is shown here, nothing suspicious to me.

-rw-r--r--  1 brady  staff   1.6K May 24 14:08 private_key

Best Answer

It's probably a bug of the Ubuntu 14.04 vagrant box. link

I changed the public key on guest OS(./ssh/authorized_keys on guest VM Ubuntu 14.04) to pair with the private key on Host OS, then vagrant works like a charm.

Another solution is deleting the existing private/public key pairs in Host OS, vagrant will generated new one. Not verified.