Hello everyone, I am Xianyu I wonder if you have ever encountered the following situation: After logging into a Linux server using a terminal (XShell, secureCRT, or MobaXterm, etc.), if there is no interaction for a period of time, the SSH session will be disconnected If some non-background commands are being executed, the disconnection of the SSH session may cause these commands to be interrupted, resulting in the inability to complete the task. So how do you keep your SSH session intact? Let's take a look Original link: https://linuxiac.com/how-to-keep-ssh-session-alive/ Why does SSH close the connection?The short answer is that it all comes down to TCP timeouts The TCP timeout is the amount of time a TCP connection or network operation waits for a response before considering the process to have failed. In Linux, the TCP timeout setting determines how long a TCP connection or operation should wait before packets are lost or the connection becomes unresponsive. TCP timeout mechanism ensures the reliability and efficiency of network communication When maintaining an SSH session, there are three key system parameters we need to pay attention to:
We can view the values of the above three parameters through the following command: tcp_keepalive_time of 600 means that the TCP connection will be maintained for 600 seconds or 10 minutes, but this does not mean that our SSH session will actually be maintained for 10 minutes. Because tcp_keepalive_probes is 9 and tcp_keepalive_intvl is 75, it means that the system will send 9 probe packets every 75 seconds (675 seconds in total), after which the session will be considered failed and closed. That is, after 675 seconds, the SSH session will terminate if there is inactivity, i.e. no typing in the terminal How to keep SSH session aliveMaintaining an SSH session is a process that involves both client and server configuration. Linux client configurationFor Linux client, we modify the ~/.ssh/config file in the home directory (create it if it does not exist) Below is the configuration
Indicates that the client sends keepalive messages to the server every 120 seconds, for a total of 30 times, that is, 120 * 30 = 3600 seconds (one hour). The SSH session will remain open for one hour. Windows client configurationFor Windows, we generally use the terminal to access the server Take secureCRT as an exampleOptions -> Session Options picture Then click [Terminal] picture Linux server configurationThe above is the configuration of the client side. Next, we will introduce the configuration of the server side. Modify the /etc/ssh/sshd_config file
As with the Linux client configuration described above, the server will maintain the SSH session for one hour (120 * 30 = 3600 seconds) Restart the SSH service after configuration |
<<: What is 5G network slicing?
>>: Redefining the Network: Navigating the World of SD-WAN
This is a big question, so I will briefly talk ab...
Since the outbreak of the pandemic last year, the...
【51CTO.com Quick Translation】I have been a comic ...
Telefénica/O2, the German telecom operator contro...
I have been engaged in operation and maintenance ...
[[357697]] After the issuance of 5G licenses on D...
Edge computing, a powerful technology that has be...
The Internet is evolving at an unprecedented pace...
New network deployments and enterprise momentum a...
[[357361]] This article is reprinted from the WeC...
In 2018, friends in the network circle have witne...
In 450 BC, Nehemiah, an official of the Persian E...
In 2018, the popularity of 5G began to rise rapid...
This month, TmhHost added dual ISP home broadband...
According to the overall arrangement for the form...