読者です 読者をやめる 読者になる 読者になる

helen's blog

ぽんこつによるぽんこつのためのぽんこつブログ

vagrantでWarning: Authentication failure. Retrying...が出まくる時

仮想環境準備

Vagrant by HashiCorp
Downloads – Oracle VM VirtualBox
A list of base boxes for Vagrant - Vagrantbox.es

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'bento/centos-6.7' could not be found. Attempting to find and install...
   default: Box Provider: virtualbox
   default: Box Version: >= 0
==> default: Loading metadata for box 'bento/centos-6.7'
   default: URL: https://atlas.hashicorp.com/bento/centos-6.7
==> default: Adding box 'bento/centos-6.7' (v2.2.7) for provider: virtualbox
   default: Downloading: https://atlas.hashicorp.com/bento/boxes/centos-6.7/versions/2.2.7/providers/virtualbox.box
==> default: Successfully added box 'bento/centos-6.7' (v2.2.7) for 'virtualbox'!
==> default: Importing base box 'bento/centos-6.7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'bento/centos-6.7' is up to date...
==> default: Setting the name of the VM: default_1470938359502_67401
==> 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: 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:
   default: Vagrant insecure key detected. Vagrant will automatically replace
   default: this with a newly generated keypair for better security.
   default:
   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...
   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 sshでパスワードを求められる

原因

vagrant1.7以降の仕様です

vagrant upすると、対象のゲストOSに対して新たな鍵のペアを生成して配置するため、
環境によってはデフォルトのinsecure_private_keyとの合わずにエラーが発生する

config.ssh.insert_key - If true, Vagrant will automatically insert a keypair to use for SSH, replacing Vagrant's default insecure key inside the machine if detected. By default, this is true.


This only has an effect if you do not already use private keys for authentication or if you are relying on the default insecure key. If you do not have to care about security in your project and want to keep using the default insecure key, set this to false.



ssh.insert_key がtrueの場合、
vagrantvagrant内のデフォルトの安全でないキーが検出されると、SSHで使用する鍵ペアを置き換える

未使用の秘密鍵の場合、デフォルトの安全でないキーを使用している場合にのみ影響がある
セキュリティを気にする必要があり、デフォルト安全でないキーを使用したい場合、これをfalseに設定してください

config.ssh - Vagrantfile - Vagrant by HashiCorp

直し方

Vagrantfileに下記追加

config.ssh.insert_key = false

追加前

vagrant ssh-config                                                                                                    ⏎
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/heleeen/work/infra/deploy_test/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL

追加後

$ vagrant ssh-config
Host default
 HostName 127.0.0.1
 User vagrant
 Port 2222
 UserKnownHostsFile /dev/null
 StrictHostKeyChecking no
 PasswordAuthentication no
 IdentityFile /Users/heleeen/.vagrant.d/insecure_private_key # ここが変わる
 IdentitiesOnly yes
 LogLevel FATAL