初回の vagrant up で延々と Authentication failure. Retrying... が発生し、リトライアウトしてしまうというネタの1バリエーションです。環境は以下の通り。
- Host OS : Windows10
- SSH Client : PuTTY
- Vagrant : 1.8.5
- VirtualBox : 5.0.26
- Guest OS : CentOS 7.x(bento/centos-7.1)
事象
D:\> mkdir laravel
D:\> cd laravel
D:\laravel> vagrant init
(作られた Vagrantfile をエディタで修正)
D:\laravel> diff.exe Vagrantfile.orig Vagrantfile
15c15
< config.vm.box = "base"
---
> config.vm.box = "bento/centos-7.1"
D:\laravel> vagrant up
(中略)
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
default: Warning: Authentication failure. Retrying...
default: Warning: Authentication failure. Retrying...
(これを30回ほど繰り返す)
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.
先に、先人の別解を示します:
-
vagrant upコマンド実行時にAuthentication failure.エラーが発生する
- デフォルトのinsecure_private_keyを使う方式
-
VagrantでSSH鍵の設定 - [Authentication failure. Retrying…]の対処策
- 鍵を作り直す方式
ただ、自分の場合はもっと単純な理由でした。まず、vagrant ssh-config で接続パラメータを確認します。
PS D:\laravel> vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile D:/laravel/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
PuTTY では OpenSSH 互換キーが使えないので、PuTTYgen.exe で private_key をインポートし、hoge.ppk を作成して秘密鍵として指定します。その後、PuTTY で vagrant@127.0.0.1:2222 に接続しようとすると、Server refused our key と怒られて、パスワード認証にフォールバックしました。
Using username "vagrant".
Server refused our key
vagrant@127.0.0.1's password:
パスワード "vagrant" でログインします。
やっぱり鍵のペアがおかしいのかなと思って作りなおしたりしていましたが、鍵の設置のため、何気に ~/.ssh を確認すると、なんと authorized_keys のパーミッションが誤っていたのを発見。即修正しました。
[vagrant@localhost ~]$ cd .ssh
[vagrant@localhost .ssh]$ ls -l
-rw-rw-r--. 1 vagrant vagrant 389 Aug 18 05:42 authorized_keys
[vagrant@localhost .ssh]$ chmod 600 authorized_keys
[vagrant@localhost .ssh]$ ls -l
-rw-------. 1 vagrant vagrant 389 Aug 18 05:42 authorized_keys
今回のケースでは、結果的にこれだけで接続できました。念のため、いったん box を消してからやり直してみても上記手順でうまくいくので、自動作成される private_key は有効のようでした。