SSHのServerAliveCountMax


24

SSHのServerAliveCountMaxは実際に何をしますか?

SSHを介してサーバーに接続するとき、接続が短時間非アクティブになった後に終了するのではなく、接続が長時間開いたままになるようにします。これは例です

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 2

あるソースから、サーバーがその応答を受信する限り、上記の設定は常に60秒ごとにサーバーに応答を送信すると聞いています。ただし、何らかの理由で応答がサーバーに送信されない場合、別のメッセージを送信しようとします。そのメッセージも失敗した場合、接続を閉じます。(これは間違っていると思う)

第二第三のソースは、しかし、別の何かを言います。非アクティブな期間がある場合、メッセージは60秒ごとにサーバーに送信されると主張しますが、2つの要求のみを送信し、その後接続を閉じます。

それでは、ServerAliveCountMaxは正確に何をしますか?

回答:


31

「これは間違っている」というあなたの気持ちは正しい。manページを参照してください

 ServerAliveCountMax
         Sets the number of server alive messages (see below) which may be
         sent without ssh(1) receiving any messages back from the server.
         If this threshold is reached while server alive messages are
         being sent, ssh will disconnect from the server, terminating the
         session.  It is important to note that the use of server alive
         messages is very different from TCPKeepAlive (below).  The server
         alive messages are sent through the encrypted channel and there‐
         fore will not be spoofable.  The TCP keepalive option enabled by
         TCPKeepAlive is spoofable.  The server alive mechanism is valu‐
         able when the client or server depend on knowing when a connec‐
         tion has become inactive.

         The default value is 3.  If, for example, ServerAliveInterval
         (see below) is set to 15 and ServerAliveCountMax is left at the
         default, if the server becomes unresponsive, ssh will disconnect
         after approximately 45 seconds.  This option applies to protocol
         version 2 only.

 ServerAliveInterval
         Sets a timeout interval in seconds after which if no data has
         been received from the server, ssh(1) will send a message through
         the encrypted channel to request a response from the server.  The
         default is 0, indicating that these messages will not be sent to
         the server.  This option applies to protocol version 2 only.

3
マニュアルページは、それInterval0無効にするための設定が明確です。ただし、に設定Maxするかどうかは明確ではありません0。無限のAlive pingを送信しますか?
GCB

それはServerAliveInterval 0を設定した場合、私には明らかではないが、接続は無期限か開いたままになります
フランチェスコ

1
@Francescoデフォルトでは、一方の端が明示的に閉じない限り、接続は永久に開いたままになります。
マイケルハンプトン

5

サーバーアライブメッセージは、トラフィックがない状態で一定時間後に接続を閉じるようにSSHサーバーが構成されている場合に役立ちます(たとえば、ほとんどの場合、SSHアクセスを提供する共有Webホスティングプロバイダーがこれを行います)。これらの2つのオプションを設定するServerAliveIntervalと、最大で1 秒ごとにパケットが送信されServerAliveCountMax、セッションが維持されます。

いずれかのオプションをに設定することの不確実性に関するコメントに答えるため0に、openssh実装のソースコードを読みました。

  • に設定ServerAliveIntervalする0とパケットは送信されませんが、TCPタイムアウトにより接続が切断されず、サーバーが非アクティブなクライアントを削除するように構成されていないと仮定して、セッションは無期限に維持されます。

  • 設定ServerAliveCountMaxにすると、0設定した場合と同じ効果があるServerAliveIntervalのを0

  • いずれかの値を負またはそれよりも大きい値INT_MAX(つまり、2,147,483,647)に設定すると、「整数値...」エラーが発生します。

  • 設定ServerAliveCountMaxの間 INT_MAX/1000+1に(すなわち2147484) INT_MAX(すなわち2147483647)はまたにどちらかの値を設定することと同じになります0

したがって、本質的に、(パケットを送信している間に)取得できるほとんどのタイムアウトはINT_MAX/1000(つまり、2,147,483)です。1セッションのタイムアウトがあり、トラフィックがまったくない場合、ほぼ25日かかります。

明らかに、SSHの他の実装では結果が異なる場合があります。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.