SSHで接続する際には多くのパラメータを指定できるのだけれど、サイト毎に異なるパラメータを都度指定するのは大変で手間がかかるのでconfigファイルに予めまとめて指定できます。
Host host1
HostName host1.example.com
User user
Port 30022
このように設定しておけば$ ssh host1とするだけでユーザ、ポート、ホストを指定して接続できます。
~/.ssh/config の書式
コマンドラインのオプション | ||
---|---|---|
Host | sshコマンドで指定する名前。 | |
HostName | ホスト名。 | |
Port | ポート番号。 | -p |
User | ユーザID。 | -l |
IdentityFile | 秘密鍵へのパスとファイル名。 | -i |
ServerAliveInterval | サーバへの疎通確認を行う。 | |
ServerAliveCountMax | ServerAliveIntervalの回数 | |
TCPKeepAlive | TCPでの疎通確認。 |
例
IdentityFileなどの共通設定はまとめておくこともできる。
IdentityFile ~/.ssh/mykey.key
ServerAliveInterval 60
ServerAliveCountMax 5
TCPKeepAlive yes
Host host1
HostName host1.example.com
User alice
Port 30022
Host host2
HostName host2.example.com
User bob
Port 40022
コメント