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
Open source has become a trend, and almost all te...
Flash was once the memory of a generation, but it...
A panel of 12 technology experts (also known as t...
While the new infrastructure is accelerating the ...
During MWC22 Barcelona, Huawei, with the theme ...
1. Overview of HTTP Status Codes 1. Concept When ...
In accordance with the requirements of blockchain...
[Original article from 51CTO.com] On February 20,...
In today’s fast-paced, hyper-connected and tech-e...
At 10 a.m. on January 20, 2022, the State Council...
Previously, we have shared information about the ...
This should be the first merchant to start the 61...
Sharktech (also known as Shark Data Center, SK Da...
Many devices on the network today, such as IP cam...
On August 3, 2021, CyberDefense Magazine, a world...