SSH의 ServerAliveCountMax


24

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

SSH를 통해 서버에 연결할 때 짧은 비활성 시간이 지난 후 연결이 끊기는 대신 오랫동안 연결이 열려 있는지 확인하려고합니다. 이것은 예입니다

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 2

나는로부터 들었어요 하나의 소스 위의 설정은 항상 60 초마다 너무 오래 서버가 응답을 수신 할 때 서버에 응답을 보낼 것입니다. 그러나 어떤 이유로 든 응답이 서버로 전달되지 않으면 다른 메시지를 보내려고 시도합니다. 해당 메시지가 실패하면 연결이 닫힙니다. (이것이 잘못되었다고 생각합니다)

그러나 두 번째세 번째 소스는 다른 말을합니다. 비 활동 기간이있는 경우 60 초마다 메시지가 서버로 전송된다고 주장하지만 2 개의 요청 만 보내면 연결이 닫힙니다.

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

답변:


31

"이것이 틀렸다"는 느낌이 맞습니다. 매뉴얼 페이지를 참조하십시오 :

 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
남자 페이지에 분명하다 Interval로 설정 0을 해제. 사용자가 설정 한 경우 그것은 분명하지 않다 Max0. 무한 Alive 핑을 보내거나 보내지 않습니까?
gcb December

ServerAliveInterval 0을 설정하면 연결이 무한정 열린 상태로 유지되는지 확실하지 않습니다
Francesco

1
@Francesco 기본적으로 연결은 한쪽 끝이 명시 적으로 닫히지 않는 한 영원히 열려 있습니다.
Michael Hampton

5

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

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

  • 설정 ServerAliveInterval하려면 0패킷을 전송하지 않습니다,하지만 연결이 때문에 TCP 시간 초과로 서버가 비활성 클라이언트를 드롭 구성되지 않았 음을 감소되지 않는다는 것을 가정 살아 무기한 세션을 유지합니다.

  • 로 설정 ServerAliveCountMax하면 0로 설정하는 것과 동일한 효과 ServerAliveInterval0있습니다.

  • 값을 음수 또는 INT_MAX2,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의 다른 구현은 다른 결과를 가질 수 있습니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.