LoginSignup
1
1

More than 5 years have passed since last update.

Windowsでboot2Dockerにssh接続

Posted at

接続構成の確認


ホスト名、ポート、ユーザーはvagrant upで起動中に出力される


...
default: SSH address: 127.0.0.1:2222
default: SSH username: docker
default: SSH auth method: private key
...

またはコマンドプロンプトで

vagrant ssh-config

このエラーが出たら

A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.

idを確認して指定する

C:\>vagrant global-status
id       name    provider   state   directory
------------------------------------------------------------------------
1f5d9fc  default virtualbox running D:/hoge

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"

C:\>vagrant ssh-config 1f5d9fc

自動で接続する

Vagrantfileを以下のようにコメントを外してvagrantを起動すると、VirtualBoxのGUI使って自動接続してくれる


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

PuTTYで接続する

バージョン0.6.0

  1. PuTTYgenを立ち上げて、%USERPROFILE%.vagrant.d\insecure_private_keyを読み込む

    既存の秘密鍵の読込 「読込」ボタンから選択する

  2. 「秘密鍵の保存」ボタンでPuTTY用のppkファイルを作成する

  3. PuTTYを立ち上げて、以下設定して「開く」ボタン押すと接続する

    カテゴリ 項目名
    セッション ホスト名 127.0.0.1
    セッション ポート 2222
    接続>データ 自動ログインのユーザー名 docker
    接続>SSH>認証 認証のためのプライベートキーファイル 保存したppkファイルパス

SSH to Vagrant box in Windows?

Git for Windowsで接続する

gitが入ってる前提

  1. Git Bashを立ち上げてssh実行

    ssh -i "$USERPROFILE\.vagrant.d\insecure_private_key" -port 2222 docker@127.0.0.1
    

    初回実行時に信頼するホストの登録か何かでyesno聞かれたらyesする

毎回指定が面倒であれば vagrant ssh-configで構成が表示されるのを確認して

mkdir $USERPROFILE\.ssh
vagrant ssh-config >> $USERPROFILE\.ssh\config

とすれば以降は次のコマンドだけで接続できる

ssh default

Windowsでvagrant upした後にsshログインする方法

1
1
0

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
1
1