最近vagrantを使用しはじめました。
vagrant upで起動に失敗することが多々あるので、
失敗原因が鍵不一致の場合の対処法をメモ。
#環境
Mac-os10.10.5
vagrant-1.8.5
#エラー内容
D2CMAC085-933:centos6 hoge$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-6.7' 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: Forwarding ports...
default: 22 (guest) => 2222 (host) (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: 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...
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...
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...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
ひたすら
default: Warning: Authentication failure. Retrying...
してました。。
#原因
vagrantのauthorized_keysの中身と、vagrantが参照している鍵が異なっていた。
#対処法
参照している秘密鍵から公開鍵を作成し、authorized_keysに書き込みます。
1.どの鍵を参照しているか確認
$ vagrant ssh-config
すると・・・
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/hoge/private_key
IdentitiesOnly yes
LogLevel FATAL
IdentityFileで鍵の参照先が分かりました!
2.private_keyから公開鍵を作成
$ ssh-keygen -yf /Users/hoge/private_key > public_key
3.作成した公開鍵の中身をauthorized_keysにコピペ
※念のためauthorized_keysを別名でコピーしておく。
$ vagrant ssh
$ cd .ssh
$ vi authorized_keys
公開鍵を書き込む
:w
:q
4.再起動
$ vagrant reload
これで無事起動しました!