18
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant up/sshに失敗したときの対処法

Posted at

Vagrantの"centos/7"boxの起動、sshログインに失敗する症状が起こったので解決方法を残しておきます。

環境

  • Windows 10 Home (64bit)
  • VirtualBox バージョン 5.2.8 r121009 (Qt5.6.2)
  • Vagrant 2.1.1

検証用のディレクトリを作ります

> mkdir sample-vm
> cd sample-vm

Vagrant作成&起動

> vagrant --version
Vagrant 2.1.1

> vagrant init centos/7
> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' is up to date...
==> default: A newer version of the box 'centos/7' for provider 'virtualbox' is
...
==> 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: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. 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      

何故かvagrant upに失敗
一応接続できるか試してみる

> vagrant ssh
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

やっぱり無理
sshコマンドも試してみる

> vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile C:/Users/username/vm/sample-vm/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL


> ssh -l vagrant -p 2222 -i "C:\Users\username\vm\sample-vm\.vagrant\machines\default\virtualbox\private_key" 127.0.0.1
The authenticity of host '[127.0.0.1]:2222 ([127.0.0.1]:2222)' can't be established.
ECDSA key fingerprint is SHA256:RW+x0y5FVoCVxlVEi7tpxhHQPyN6mSrNtlC4lUKY1+0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[127.0.0.1]:2222' (ECDSA) to the list of known hosts.
Load key "C:/Users/username/vm/sample-vm/.vagrant/machines/default/virtualbox/private_key": Permission denied
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

できなーい!!

default: Warning: Remote connection disconnect. Retrying... とか
Permission denied (publickey,gssapi-keyex,gssapi-with-mic). とか
でググったけど解決せず・・・

Permission deniedてなんだ?Linuxでもないのにパーミッションなんてあんのかよ!
とかいろいろ悩んだ結果、近くの人に相談したところ・・・

解決方法

private_key のある階層(C:/Users/username/vm/sample-vm/.vagrant/machines/default/virtualbox/private_key)まで移動し、右クリック→プロパティ

aaa-1.png

セキュリティタグを選んで、編集ボタン

aaa-2.png

追加ボタンから

aaa-3.png

ユーザー名を入力したら、名前の確認をしてOK

aaa-4.png

今追加したユーザーを選んで、フルコントロールをチェック(これで全部のチェックがつく)して適用
(読み取りだけでもOKだと思います)

aaa-5.png

同じ要領で、元からあったユーザーを選びすべてのチェックを外してOK。(理由は後述)

↓最終的にこんな感じになります。

aaa-6.png

> vagrant halt
...

> vagrant up
...

> vagrant ssh
Last login: Tue Jun 12 08:17:52 2018 from 10.0.2.2
[vagrant@localhost ~]$

できた!!
vagrant halt > up を挟んでいるのは最初の vagrant up が途中でこけて準備が最後まで出来ていないためです。

sshコマンドでもちゃんとログイン出来ました

>ssh -l vagrant -p 2222 -i "C:\Users\username\vm\sample-vm\.vagrant\machines\default\virtualbox\private_key" 127.0.0.1
Last login: Tue Jun 12 07:54:41 2018 from 10.0.2.2
[vagrant@localhost ~]$

原因

半年前くらいには起こらなかった症状なので、Windowsアップデートでファイルへのアクセス権限チェックが厳しくなったのだろうと(自分の中で)いう結論にしました。

詳しい方がいらっしゃれば、コメント頂けるとうれしいです。

ちなみに・・・

他のユーザー(最初設定されていたユーザー)に権限が残っていると、ほかのユーザーを減らせという警告がでます。
sshクライアントソフトを使う場合は問題なく使えることもあるみたいなので、ここはケースバイケースで。

>ssh -l vagrant -p 2222 -i "C:\Users\username\vm\sample-vm\.vagrant\machines\default\virtualbox\private_key" 127.0.0.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'C:\\Users\\username\\vm\\sample-vm\\.vagrant\\machines\\default\\virtualbox\\private_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "C:\\Users\\username\\vm\\sample-vm\\.vagrant\\machines\\default\\virtualbox\\private_key": bad permissions
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
18
22
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?