Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法

Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法

Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法

Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法
最終更新日:2020.08.26

Vagrantでローカル環境構築時default: Warning: Authentication failure. Retrying...エラーがでまくって困ったので対処法メモです。

環境

MacOS High Sierra
Vagrant 2.2.4

エラー内容

Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> default: Clearing any previously set network interfaces…
==> default: Preparing network interfaces based on configuration…
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports…
default: 80 (guest) => 8000 (host) (adapter 1)
default: 1080 (guest) => 1080 (host) (adapter 1)
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…

どうやらSSH接続のところでコケている模様。
default: Warning: Authentication failure. Retrying...が何度も表示されてvagrant upが完了しませんでした。
vagrant sshで仮想マシンに入ることはできます。

対処法

その1  .ssh フォルダのパーミッション設定を変えてみる

default: Warning: Authentication failure. Retrying...がでている途中に
ctl+cを押して処理を一旦ストップ。
vagrant sshでログインしパスワードをvagrantと入力。

[vagrant@localhost ~]$とログイン完了したら以下のコマンドで.ssh フォルダのパーミッション設定を変更します。

$ chmod 0700 /home/vagrant/.ssh
$ chmod 0600 /home/vagrant/.ssh/authorized_keys
$ chown -R vagrant /home/vagrant/.ssh

Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法

結果…未解決!

参考にしたページ
https://qiita.com/tateren/items/dd0da1a5910de68c266e
http://kayakuguri.github.io/blog/2017/04/24/vagrant-authentication-error/
https://mseeeen.msen.jp/fix-authentication-failure-in-vagrant-1-8-5/

うーん解決しませんでした。パーミッションではなかった模様。次の手段を調べます。

なこ
えーーあかんかった…

その2  自分のPCとローカル環境内の公開鍵を同じにしてみる

自分のPC内で管理しているプライベートキーと仮想環境の公開鍵が不一致の可能性。

[vagrant@localhost ~]$からexitでログアウトしvagrant ssh-configと入力。
仮想環境がどこのプライベートキーを参照しているか調べます。

Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/hogehoge/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL

IdentityFile /Users/hogehoge/.vagrant.d/insecure_private_key部分がPC内のプライベートキー格納場所です。

$ ssh-keygen -y -f /Users/hogehoge/.vagrant.d/insecure_private_key

上のコマンドで公開鍵をファイルの中をチェックします。中身はこんな感じ(380文字程度)。

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y・・・・・・・・・==

上で表示されたpublic_keyファイルの中身をコピーしておきます。

vagrant sshでログインしパスワードをvagrantと入力。
vagrantマシンにログインします。

authorized_keysファイルに公開鍵を追加します。
上ののssh-keygenコマンドからssh-rsa行全体をコピーしてここに貼り付けます。一番最後の Vagrant は消さないようにしてください!
最後はControl-Dを押してコマンドを終了する必要があります。

vi /home/vagrant/.ssh/authorized_keys

exitでログアウトしvagrant reload

Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法

結果…未解決!

参考にしたページ
https://qiita.com/d2cdot-mmori/items/1c340f175ae510e4456a

うーん解決しませんでした。これじゃないのん?ググっても他の答えないんですが・・・

その3  Vagrant環境の公開鍵を更新後パーミッション変えてみる

default: Warning: Authentication failure. Retrying...がでている途中に
ctl+cを押して処理を一旦ストップ。
vagrant sshでログインしパスワードをvagrantと入力。

[vagrant@localhost ~]$とログイン完了したら以下のコマンドでVagrant環境の公開鍵を更新します。

$ wget –no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
$ chmod 0700 /home/vagrant/.ssh
$ chmod 0600 /home/vagrant/.ssh/authorized_keys
$ chown -R vagrant /home/vagrant/.ssh

Vagrantでローカル環境構築時「default: Warning: Authentication failure. Retrying…」エラーが出る時の対処法

結果…解決!
Bringing machine ‘default’ up with ‘virtualbox’ provider…
==> 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: hostonly
==> default: Forwarding ports…
default: 80 (guest) => 8000 (host) (adapter 1)
default: 1080 (guest) => 1080 (host) (adapter 1)
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: Machine booted and ready!
==> default: Checking for guest additions in VM…
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 5.1.14
default: VirtualBox Version: 6.0

私はこれで解決しました!boxがパッケージ化してあったので古かったのかな。

その4 vagrantfile内に公開鍵の場所と更新不要の旨を書き込む

config.vm.network “private_network”, ip: “192.168.33.13”, auto_config:false
config.ssh.insert_key = false
config.ssh.private_key_path = “/Users/hogehoge/.vagrant.d/insecure_private_key”

こちら試してないですが、ぐぐったら解決法として沢山出てきたのでメモ