質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Q&A

1回答

1632閲覧

vagrantで立てたVMにPuTTYでSSH接続できない

Alek3

総合スコア7

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

1グッド

1クリップ

投稿2017/12/26 15:33

編集2022/01/12 10:55

###前提・実現したいこと
実現したいことはタイトルの通り、
vagrant(virtual box前提)で立てた仮想マシンにWindowsからSSH接続できるようにすることです。

###発生している問題・エラーメッセージ

vagrant up 時のメッセージ

vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'ubuntu/trusty64' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Fixed port collision for 22 => 2222. Now on port 2200. ==> 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) => 2200 (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:2200 default: SSH username: vagrant default: SSH auth method: private key

PuTTYの設定

session host name: 127.0.0.1 port: 2200 connection > data Auto-login username: vagrant connection > SSH > Auth private key file for authentication: insecure_private_keyから作成した.ppkファイル

発生エラー……PuTTYが起動後、何の文字も画面に表示されず、しばらくして以下のエラーが出る

Network error: Software caused connection abort

vagrant up したコマンドプロンプトの方は、数分すると以下のメッセージが出ます。

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.

最後に、vagrantfileは以下の通りです。

# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = "ubuntu/trusty64" config.ssh.insert_key = false # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # NOTE: This will enable public access to the opened port # config.vm.network "forwarded_port", guest: 80, host: 8080 # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine and only allow access # via 127.0.0.1 to disable public access # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" # Create a private network, which allows host-only access to the machine # using a specific IP. config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "../data", "/vagrant_data" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # # View the documentation for the provider you are using for more # information on available options. # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. # config.vm.provision "shell", inline: <<-SHELL # apt-get update # apt-get install -y apache2 # SHELL end

(追記)vagrant up 後にvagrant sshしたときのメッセージは以下の通りです。

ssh_exchange_identification: read: Connection reset by peer

なお、コマンドを打ってからメッセージが出るまで1分ほどかかります。

piroq👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

vagrant(virtual box前提)で立てた

上記は、既にvagrant sshができてたということでしょうか?
config.ssh.insert_key = falseなので、Vagrant認証に失敗している可能性があります。

どういう構成なのかにもよりますが、普通はvagrant init時に.vagrant/machines/default/virtualbox/*に秘密キー(private_key)やマシンIDなどを自動的に設定します。そして、vagrant ssh時に自動的にSSH認証する仕組みです。これに成功していれば、下記のようにSSHログインができます。

bash

1ssh -i .vagrant/machines/default/virtualbox/private_key vagrant@localhost -p 2200

また、Vagrant起動が2台目ではないのであれば、Vagrantがどこかでハングアップしている可能性があります。通常、SSH1代目はフォワードポート2222で、2台目はポート2200なので。

問題が解決しないのであれば、バーチャルボックスのネットワーク設定も確認したほうがよいです。ホストオンリーネットワークを作り直してみたり、ネットワークアダプのIPアドレスに192.168.33.10が使われていないことを確認します。そして、ファイヤーウォールもブロックされていないか確認します。

エラー翻訳(意訳)

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.

マシン起動時にタイムアウトしました。この意味は、Vagrantの設定(config.vm.boot_timeout 値)の時間の間ゲストマシン(仮想マシン)と通信ができていたということです。

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.

これを見れば、Vagrantは(仮想)マシンに接続中に起きたエラーだとわかるはずです。これらのエラーは通常、何が間違っていたのかについて良いヒントになります。

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.

もしカスタムBOXを使っている場合は、ネットワークが確実に動いていることを確認すれば、(仮想)マシンに接続できるでしょう。これらの(カスタム)BOX中でネットワークが正常にセットアップされていないというよくある問題です。
また、認証設定が正常にセットアップされているかも確認してください。

If the box appears to be booting properly, you may want to increase

the timeout ("config.vm.boot_timeout") value.

もしBOXが正常に起動するはずなのであれば、タイムアウト(config.vm.boot_timeout)値を増やしてみてください。

投稿2017/12/26 17:11

Tomak

総合スコア1652

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Alek3

2017/12/27 14:10

ご回答ありがとうございます。質問を更新しましたが、vagrant sshは失敗していると思われます。補足に書きそびれましたが、vagrant ssh は vagrant up した後に別のコマンドプロンプトを立ち上げて実行しています。
Tomak

2017/12/28 05:15

下記は、ネットワーク設定が正常でない場合にでます。また、ファイヤーウォールなどで接続がブロックされている場合にも表示されます。ネットワーク接続確立の前にそのネットワークに接続できないという意味です。 ---- ssh_exchange_identification: read: Connection reset by peer 自動的に作成される「.vagrant/machines/default/virtualbox/private_key」を編集したり、「vagrant init」してからパスの移動をしたりしてはいけません。 初期インストールなのであれば、下記をコメントアウトしてみてはいかがでしょうか? ---- #config.ssh.insert_key = false あとは、VirtualBoxのネットワークアダプタを設定した場合は「192.168.33.10」が既に設定されていないことを確認します。VagrantではネットワークのIP設定はVagrantが勝手にやってくれます。VirtualBoxのネットワークアダプを設定していない場合はNAT設定が正しいかを確認します。 例えば、192.168.33.10を仮想マシンIPに振りたい場合は下記のように確認します。 ---- 1. VirtualBoxを起動 2. セットアップ中の「box名_default_xxxx」を選択 3. メインのネットワークがどのVirtualBox Host-Only Ethernet Adapterを使用しているか確認 4. ファイル>環境設定 5. ネットワーク(左側)選択 6. ホストオンリーネットワークタブ選択 7. 3.で使用しているアダプタをダブルクリック(例:VirtualBox Host-Only Ethernet Adapter #2) 8. 下記のような設定を確認(IPは「192.168.33.10」以外であればなんでもOK) IPv4 アドレス:192.168.33.1 IPv4 ネットマスク:255.255.255.0 DHCPサーバー>サーバーを有効化:OFF
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問