ゆず日記

戦う Vimmer 兼 Dvorakユーザ 兼 Kinesisユーザ 兼 おぺらー が戦わないブログ

ssh コマンドで Vagrant に ssh 接続したお話。

vagrant sshvagrant up するディレクトリにいないとできないので、ssh hoge でも接続できるようにする。

手順

.ssh/config に以下を追加

Host hoge
  HostName 192.168.xxx.xxx
  Port 2222
  IdentityFile ~/.vagrant.d/insecure_private_key
  User vagrant

config に必要な内容は、vagrant ssh-configから確認できる。 後は ssh hoge でどのディレクトリに居てもログイン可能。

補足

$ vagrant ssh-config で .ssh/config に設定すべき内容と同等のものが取れる。

$ vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/ああああ/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

Host名の “default” は raspberry-devbox/Vagrantfile at master · nickhutchinson/raspberry-devbox の場合だと “nox" になっていたので、

config.vm.define :nox do |box| のように書いておけば、

$ vagrant ssh-config >> ~/.ssh/config

のような感じに楽に追加できそうだ。