SSH의 ServerAliveCountMax

SSH의 ServerAliveCountMax

SSH의 ServerAliveCountMax는 실제로 무엇을 수행합니까?

SSH를 통해 내 서버에 연결할 때 짧은 기간 동안 활동이 없으면 연결이 끊어지는 대신 오랜 시간 동안 연결이 열려 있는지 확인하려고 합니다. 이것이 예시이다

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 2

나는 에게서 들었다하나의 소스위의 설정은 서버가 해당 응답을 수신하는 한 항상 60초마다 서버에 응답을 보냅니다. 그러나 어떤 이유로든 응답이 서버로 전달되지 않으면 다른 메시지를 보내려고 시도합니다. 해당 메시지도 실패하면 연결이 닫힙니다. (이건 잘못된 것 같아요)

그만큼두번째그리고제삼그러나 소스는 다른 것을 말합니다. 그들은 일정 기간 동안 활동이 없으면 60초마다 서버에 메시지가 전송되지만 2개의 요청을 통해서만 전송되고 연결이 종료된다고 주장합니다.

그렇다면 ServerAliveCountMax는 정확히 무엇을 수행합니까?

답변1

"이건 틀렸어"라는 느낌이 맞습니다.매뉴얼 페이지를 참조하세요:

 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.

답변2

서버 활성 메시지는 트래픽이 없는 일정 기간 후에 연결을 닫도록 SSH 서버를 구성한 경우에 유용합니다(예를 들어 SSH 액세스를 제공하는 공유 웹 호스팅 공급자는 거의 항상 이 작업을 수행합니다). 이 두 가지 옵션을 설정하면 ServerAliveInterval매초마다 최대 횟수 동안 패킷이 전송되어 ServerAliveCountMax세션이 활성 상태로 유지됩니다.

두 옵션 중 하나를 로 설정할 때의 불확실성에 대한 의견에 답변하기 위해 구현 0의 소스 코드를 읽었으며 openssh여기에 내가 본 내용이 나와 있습니다.

  • ServerAliveInterval로 설정 하면 0패킷이 전송되지 않지만 TCP 시간 초과로 인해 연결이 끊어지지 않고 서버가 비활성 클라이언트를 삭제하도록 구성되지 않았다고 가정하면 세션이 무기한 유지됩니다.

  • ServerAliveCountMax로 설정하는 것은 으로 설정하는 것과 0동일한 효과를 가집니다 .ServerAliveInterval0

  • 값을 음수 또는 그보다 큰 값 INT_MAX(예: 2,147,483,647) 으로 설정하면"정수값..."오류.

  • (예: 2,147,484) ~ (예: 2,147,483,647) ServerAliveCountMax사이로 설정하는 것은 두 값 중 하나를 로 설정하는 것과 동일합니다 .INT_MAX/1000+1INT_MAX0

따라서 본질적으로 (패킷을 보내는 동안) 얻을 수 있는 최대 시간 초과는 INT_MAX/1000(예: 2,147,483)입니다. 시간 초과가 발생 1하고 세션에 트래픽이 전혀 없으면 거의 25일이 소요됩니다.

분명히 다른 SSH 구현에서는 다른 결과가 나타날 수 있습니다.

관련 정보