接続構成の確認
ホスト名、ポート、ユーザーは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
-
PuTTYgenを立ち上げて、%USERPROFILE%.vagrant.d\insecure_private_keyを読み込む
既存の秘密鍵の読込 「読込」ボタンから選択する
-
「秘密鍵の保存」ボタンでPuTTY用のppkファイルを作成する
-
PuTTYを立ち上げて、以下設定して「開く」ボタン押すと接続する
|カテゴリ|項目名|値|
|:--|:--|:--|
|セッション|ホスト名|127.0.0.1|
|セッション|ポート|2222|
|接続>データ|自動ログインのユーザー名|docker|
|接続>SSH>認証|認証のためのプライベートキーファイル|保存したppkファイルパス|
Git for Windowsで接続する
gitが入ってる前提
-
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ログインする方法](http://dqn.sakusakutto.jp/2013/08/windows_vagrant_ssh.html)