How to Keep Alive SSH Sessions

Source: Internet
Author: User
Tags keep alive openssh server root access

How to Keep Alive SSH Sessions

Many NAT firewalls time out idle sessions after a certain period of time to keep their trunks clean. Sometimes the interval between session drops is a hours, but on many commodity firewalls, connections was killed after as little as seconds. To avoid has your SSH sessions become unresponsive after e.g. 5 minutes, do the following:

On Windows (PuTTY)

In your session properties, go to Connection and under sending of NULL packets to keep session AC tive, set Seconds between keepalives (0 to turn off) to e.g. (5 minutes).

On Linux (SSH)

To enable the Keep alive System-wide (root access required), edit, to /etc/ssh/ssh_config set the settings for just your user, edit (Create the file if it doesn ' t exist). Insert the following:

Host *    serveraliveinterval    Serveralivecountmax 2

You can also make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config :

Clientaliveinterval 300ClientAliveCountMax 2

These settings would make the SSH client or server send a null packet to the other side every seconds (5 minutes), and give up if it doesn ' t receive any response after 2 tries, at which point the connection is Likely to has been discarded anyway.

From the ssh_config Mans page:

Serveralivecountmax
Sets the number of server alive messages (see below) which could be sent without SSH (1) receiving all messages back from the Server. If this threshold was reached while server alive messages be being sent, SSH would disconnect from the server, terminating The session. It is a important to note, the use of server alive messages are very different from tcpkeepalive (below). The server alive messages is sent through the encrypted channel and therefore won't be spoofable. The TCP keepalive option enabled by Tcpkeepalive is spoofable. The server alive mechanism is valuable when the client or server depend on knowing when a connection have become inactive.

The default value is 3. If, for example, Serveraliveinterval (see below) are set to and Serveralivecountmax are left at the default, if the serve R becomes unresponsive, SSH would disconnect after approximately seconds. This option applies to Protocol version 2 only; In Protocol version 1 there was no mechanism to request a response from the server to the server alive messages, so disconn Ection is the responsibility of the TCP stack.

Serveraliveinterval
Sets a timeout interval in seconds after which if no data have been received from the server, SSH (1) would send a message th Rough the encrypted channel to request a response from the server. The default is 0, indicating that these messages would not being sent to the server, or if the Batchmode option is set. This option applies to Protocol version 2 only. Protocolkeepalives and Setuptimeout is debian-specific compatibility aliases for this option.

How to Keep Alive SSH Sessions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.