Solutions SSH automatically disconnect after reconnection

Note : This article comes from bloggers: chloneda

Problem Scenario

SSH remote terminal connection service, would often automatically disconnected after the long period of inactivity, or no response, not through the keyboard, only be forced to disconnect and reconnect.

Is there a way to keep SSH automatically reconnect after disconnecting the connection, or disconnect it? some!

Solution

Option One: The client sends a heartbeat

Under Linux / Unix, edit ssh configuration file:

vim /etc/ssh/ssh_config

Add the following to the file:

ServerAliveInterval 20
ServerAliveCountMax 999
  • ServerAliveInterval: indicates how many seconds interval, transmitting from the client to the server heartbeat (Alive detection).
  • ServerAliveCountMax: After the server represents how many beats no response, the client will consider an SSH connection to the server has been disconnected, and then disconnect.

The above-described configuration, said: every 20 seconds, heartbeat sent to the server. If no more than 999 times the transmission request is successful, the disconnected from the active server.

Scheme II: The server sends a heartbeat

On the server side, edit the configuration file ssh:

sudo vim /etc/ssh/sshd_config

Add the following to the file:

ClientAliveInterval 60
ClientAliveCountMax 3
  • ClientAliveInterval: represent every number of seconds, it is sent from the server to the client heartbeat.
  • ClientAliveInterval: means that the client does not respond after the number of beats, the server will assume that the client has been disconnected, and then disconnect.

The above-described configuration, said: every 60 seconds, the server side to the client sends a heartbeat. If the client request is not more than 3 times the response, the client connection is disconnected from the server.

Therefore, a total allowed response time is not less than 3 * 60 = 180 seconds.

In fact, rely on ssh client periodically send heartbeat, putty, SecureCRT, XShell tools also have this feature.

Finish!

Guess you like

Origin www.cnblogs.com/chloneda/p/ssh-connect.html