Solution to ssh timeout disconnection

Source: Internet
Author: User
Tags ssh secure shell ssh server
Article Title: How to Solve ssh timeout disconnection. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

When using SSH Secure Shell to connect to Linux, if there is no operation in a few minutes, the connection will be disconnected and you must log on again. The same operation is repeated each time, which is annoying, this article summarizes two solutions.

  Method 1: change the configuration file/etc/ssh/sshd_config of the ssh server.

ClientAliveInterval specifies the time interval for the server to request messages from the client. The default value is 0, and no message is sent. ClientAliveInterval 60 indicates that the request is sent once every minute, and then the client responds, so that the persistent connection is maintained. The strange thing here is that the client does not actively initiate a request to maintain the connection (such as FTerm and CTerm), but the server needs to take the initiative first.

In addition, for ClientAliveCountMax, use the default value 3. ClientAliveCountMax indicates that after the server sends a request, the client automatically disconnects when the number of times the client does not respond to a certain value. Normally, the client does not respond.

ClientAliveCountMax

Sets the number of client alive messages (see below) which may be sent without sshd (8) Inserting ing any messages back from the client. if this threshold is reached while client alive messages are being sent, sshd will disconnect the client, terminating the ses-sion. it is important to note that the use of client alive messages is very different from TCPKeepAlive (below ). the client alive messages are sent through the encrypted channel and therefore will not be spoofable. the TCP keepalive option enabled by TCPKeepAlive is spoofable. the client alive mechanic is valuable when the client or server depend on knowing when a connection has become inactive. the default value is 3. if ClientAliveInterval (see below) is set to 15, and ClientAliveCountMax is left at the default, unresponsive SSH clients will be disconnected after approximately 45 seconds. this option applies to protocol version 2 only.

ClientAliveInterval

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

Vim/etc/ssh/sshd_config

Find the ClientAliveInterval parameter. If not, add a line.

The value of ClientAliveInterval is second. For example, if you set it to 540, It is 9 minutes.

ClientAliveInterval 540

For ClientAliveCountMax

If the client is found to have no corresponding value, a timeout is determined. This parameter sets the number of times that timeout is allowed, for example, 10.

ClientAliveInterval 540

ClientAliveCountMax 10;

The timeout value is 5400 seconds = 90 minutes.

  Method 2: configure the client

1. ssh commands in linux

Vim/etc/ssh/ssh_config

Then, find the ServerAliveInterval parameter in it. If you don't have one, add it yourself. The parameters have the same meaning and are in seconds, for example, 9 minutes:

ServerAliveInterval 540

2 SecureCRT

Set anti-idle, as shown in

3 Putty

Enable putty keepalive

Putty-> Connection-> Seconds between keepalives (0 to turn off). The default value is 0, which is changed to 60.

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.