Why SSH is automatically disconnected

Source: Internet
Author: User

Method One:

With PUTTY/SECURECRT for 3 minutes or so without input, automatically disconnect, and then must re-login, very troublesome.

In the online search a lot of information, found that there are many reasons, environmental variables tmout caused, Clientalivecountmax and clientaliveinterval setup problems or even firewall settings. So you can try this:

1, Echo $TMOUT
If blank is displayed, it means that there is no setting, equal to using the default value of 0, and should normally not time out. If it is greater than 0, you can set it to 0 in a file such as/etc/profile.
Definition:TMOUT:If set to a value greater than zero, the value was interpreted as the number of seconds to wait for Inpu T after issuing the primary prompt. Bash terminates after waiting for, then number of seconds if input does not arrive.
2. Clientaliveinterval 60
Adding Clientaliveinterval in/etc/ssh/sshd_config, clientaliveinterval specifies the time interval for server-to-client request messages, which is 0 by default. Do not send. Instead, Clientaliveinterval 60 indicates that it is sent every minute, and then the client responds, so that it remains long connected. Here is the strange place is: not the client actively initiates the request to keep the connection (such as Fterm, cterm, etc.), but requires the server first initiative.

Also, for Clientalivecountmax, use the default value of 3. Clientalivecountmax indicates that the client does not respond to a certain number of times after the server makes a request and disconnects automatically. Normally, the client does not respond.

Clientalivecountmax
Sets the number of the client Alive messages (see below) which could be
sent without sshd (8) Receiv ing any messages back from the client.
If This threshold was reached while client alive messages be
being sent, sshd would disconnect the client, Terminati ng the ses-
Sion. It is important to note, the use of the client Alive mes-
Sages are very different from tcpkeepalive (below). The client
Alive messages is sent through the encrypted channel and there-
Fore is not being spoofable. The TCP keepalive option enabled by
Tcpkeepalive is spoofable. The client alive mechanism is valu-
able if the client or server depend on knowing when a connec-
tion have become Inactive.

The default value is 3. If Clientaliveinterval (see below) are
set to, and Clientalivecountmax are left at the default, unre-
sponsive SSH Clients'll is disconnected after approximately
seconds. This option applies to Protocol version 2 only.

Clientaliveinterval
Sets a timeout interval in seconds after which if no data have
Been received from the client, sshd (8) would send a message
Through the encrypted channel to request a response from the
Client. The default is 0, indicating that these messages would
Not being sent to the client. This option applies to Protocol ver-
Sion 2 only.
3. Enable Putty KeepAlive
Putty, Connection, Seconds between keepalives (0 to turn off), default is 0, change to 60

Method Two:

The English name of SSH is secure Shell. By using SSH, you can encrypt all transmitted data so that the "man-in-the-middle" attack is not possible, and it can prevent DNS and IP spoofing. An additional benefit is that the transmitted data is compressed so that the transfer speed can be speeded up. SSH has a number of features that can replace Telnet and provide a secure "channel" for FTP, pop, and even PPP.
The so-called "middleman" attack means that the "middleman" is impersonating a real server to receive your data to the server, and then impersonating you to pass the data to the real server. The data transfer between the server and you is a very serious problem after the hands and feet of the "middleman".
China e-Dynamic Network (www.edong.com) by virtue of high-quality service experience and superb professional technology by a lot of enterprise application customers favor. IDC has proposed two ways to solve the SSH timeout disconnection solution for your reference:
1. Configure the server

#vi/etc/ssh/sshd_config

1) Find the Clientaliveinterval parameter, if you do not add a line

The value is seconds, for example, if you set it to 120, it is 2 minutes.
Clientaliveinterval 120

2) Clientalivecountmax
Refers to the time-out, which sets the number of times a timeout is allowed if the client is found to be not corresponding. such as 3, 5 and other customizations.

After modifying the two parameters, the following:

Clientaliveinterval 120
Clientalivecountmax 0 # # #在不允许超时次数
Reload the sshd service. Exit the client and log in again to verify.

2. Configure the Client

#vi/etc/ssh/ssh_config

and find the inside.
Serveraliveinterval

Parameters, if not, you also add one yourself, the parameters of the same meaning, are the number of seconds, such as 5 minutes.

Serveraliveinterval 300

Why SSH is automatically disconnected

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.