Help us understand the problem. What is going on with this article?

VagrantのAuthentication failure.エラーへの対応

More than 3 years have passed since last update.

事象内容

vagrant 1.8をインストールしテスト環境を作成したところ、
以下のエラーが出て一向にVMの起動が進まない。

$ vagrant -v
Vagrant 1.8.5
$ vagrant up
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: 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: Warning: Remote connection disconnect. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
(以下略)

対応方法

まずはVM側のフォルダの許可権を変更。

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

この状態でVMを起動。

$ vagrant up
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: 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: 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: 4.3.28
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/yuta/vagrant/centos7

・・・解決したようだ。

2016/09/02追記

authorized_keysファイルはの許可権は600にする必要がある。(参考に追加)

また仮想マシンをsuspend -> resumeした時にまたまた認証のエラーが出ていたので公開鍵を置き換えないように記述を追加する。

Vagrantfile
## 公開鍵を置き換えないようにする。
config.ssh.insert_key = false

なお、/var/log/secureに認証エラーのログも出力されている。

Aug 30 16:05:21 localhost sshd[3371]: Connection closed by 192. 168.0.1 [preauth]
Aug 30 16:05:21 localhost sshd[3373]: Authentication refused: bad ownership or modes for file /home/vagrant/.ssh/authorized_keys

参考

http://qiita.com/shyse/items/9ec50b868b90f847c75f
http://qiita.com/HamaTech/items/21bb9761f326c4d4aa65
http://takuya-1st.hatenablog.jp/entry/20090216/1234742055

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away