Skip to content

Instantly share code, notes, and snippets.

@toyokawah
Created January 5, 2020 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyokawah/ea3270eeaf03d612349ab91670e53f7e to your computer and use it in GitHub Desktop.
Save toyokawah/ea3270eeaf03d612349ab91670e53f7e to your computer and use it in GitHub Desktop.
ssh 接続をタイムアウトしないようにする

ssh 接続をタイムアウトしないようにする

  • 目次 [非表示]
  • 1 OpenSSH (Linux, OS X)
  • 1.1 クライアント側の設定
  • 1.2 サーバ側の設定

ssh の接続が切れないよう(タイムアウトしないよう)にするには、クライアント側かサーバー側のどちらかに以下の設定をすればよい。 サーバーとクライアント両方に設定しても問題はない。

クライアント側の設定

sshd サーバと応答確認する間隔 ServerAliveIntervalを設定する。 ServerAliveInterval のデフォルト値は 0 で、デフォルトでは応答確認しないようになっている。

  • /etc/ssh/ssh_config OR ~/.ssh/config
ServerAliveInterval 15

設定した時間に応答がないと、ServerAliveCountMax の回数(デフォルト値: 3)応答確認し、応答がないとタイムアウトする。

例えば ServerAliveInterval 15 に設定すると 15秒毎にサーバーにメッセージを送り、ServerAliveCountMax のデフォルト回数である 3回まで繰り返す。つまり、サーバーが応答しなくなった後 45秒後に接続を切断する。

サーバ側の設定

sshd サーバ側でも同じような設定をすることができる。サーバ側ではClientAliveIntervalを設定する。

  • /etc/ssh/sshd_config
ClientAliveInterval 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment