LoginSignup
163
159

More than 5 years have passed since last update.

Vagrant ssh-configでvagrant sshを快適にする

Last updated at Posted at 2014-06-04

vagrant sshコマンドでvagrantにログインするときにレスポンスが悪くていらいらしちゃってる人は、この設定すると幸せになれるかもしれません。

Vagrantfileを編集する

下記の行を追加する
hostの番号は任意。OSが使用中のポートと被らないポート番号を指定しましょう。

Vagrantfile
  config.vm.network "forwarded_port", guest: 22, host: 2210

そしてvagrant up

terminal
vagrant up

vagrant ssh-configする

Vagrantfileが存在するディレクトリで以下のコマンドを実行。
~/.ssh/configに設定を入れる
※[myHost]部は任意の名前を入れてください

terminal
vagrant ssh-config --host [myHost] >> ~/.ssh/config

出力されたconfigの内容を確認

config
Host myHost
  HostName 127.0.0.1
  User vagrant
  Port 2210
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile {private_key_path}
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes

※複数のvagrantに同様の設定をしたいときは、Vagrantfileに記載したhostのポート番号を変えればいくつでも設定可能です。

vagrantディレクトリから移動し、sshコマンドでvagrantにアクセス。

terminal
cd # ホームディレクトリに移動
ssh myHost # sshコマンドでmyHostに接続
Last login: Wed Jun  4 10:42:46 2014 from 10.0.2.2
[vagrant@localhost ~]$

ログインの応答がとても早くストレス無くsshできますので、お試しくださいませ。

163
159
6

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
163
159