~/.ssh/configを利用してSSH接続を簡略化する

ローカルからSSHでサーバーに接続するときいちいちssh [user]@[host] -i [keyPath] -p [port]とか打ってられないので~/.ssh/configに情報をまとめておくと簡単に接続できるようになります。

~/.ssh/configのサンプル


Host remote
  HostName 127.0.0.1
  User centos
  IdentityFile /Users/name/.ssh/example.pem
  Port 5555
  ServerAliveInterval 300
  TCPKeepAlive yes

上記の場合ssh remoteとコマンドを打つだけで接続できるようになります。

以下、各オプションの説明。

Host
ホストにアクセスするための名前。短くするのがおすすめ。
HostName
ホストのIPアドレス
User
ホストにアクセスするユーザー名
IdentityFile
鍵ファイルのパス
Port
ポート番号
ServerAliveInterval
TCPKeepAliveする間隔。秒数で指定。
TCPKeepAlive
yes | no yesにするとServerAliveIntervalで指定した秒数ごとに通信を確認する。接続を切らさないための設定。