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

けつあご日記

こんちは.菊地です.なんか浅ーいことをいろいろ書きます

【決定版】vagrant upでAuthentication failureが出続ける@Mac【なれない日記20160823】

なれない日記

Vagrantはwindows時代からずっとうまくいかない...つらい...

普通にVagrantとVirtualBoxをインストールしたあと,boxを指定してinitしてvagrant upしたら,

$ 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...
(ずっと続く...)

control+cで止めて,vagrant statusを見ると起動はできている.vagrant sshするとなぜかパスワードを求められる.

vagrant@127.0.0.1's password: 

"vagrant"と打てばログインできるが,以上を毎回やるのは面倒すぎる...

調べると解決策がたくさん出てくるが,うまくいかないのも多かった.何個もやってやっとうまく行った.

結局,initしたあとにVagrantfileに

config.ssh.insert_key = false

を追加するだけでいけた.なんやねん...

$ 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: Remote connection disconnect. Retrying...
==> 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.0.20
    default: VirtualBox Version: 5.1
==> default: Mounting shared folders...
    default: /vagrant => /Users/hkikuchi/Vagrant/CentOS67
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

$ vagrant ssh
Last login: Tue Aug 23 05:49:16 2016 from 10.0.2.2
[vagrant@localhost ~]$

参考リンク
qiita.com

↑ではそのあと公開鍵を配置しているが,どうやらこれは自動で行われたらしく,必要なかった.パーミッションの変更も必要ない


↓では公開鍵を消してしまうとアカンとか,sshdの設定次第でアカン,と言っているが,私の場合違った.
公開鍵は消してない.sshdの設定は全くいじっていない(パスワード認証は"#PasswordAuthentication no"のままになっている)が,以上の通りにすればうまく行った.

qiita.com