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
[[348632]] Recently, the three major operators ha...
operating system Manjaro is a distribution based ...
SmartHost has just launched a Memorial Day 40% OF...
edgeNAT has sent out promotions for the Mid-Autum...
According to information from the official websit...
Large-scale production scenarios involve a large ...
The intelligent lighting equipment distributed on...
In early 2020, the coronavirus pandemic hit IT li...
Ansible is a powerful automated operation and mai...
[[284708]] A few days ago, I attended the second ...
On September 5, 2017, during HUAWEI CONNECT 2017,...
[[397765]] This article is reprinted from the WeC...
October 2019 is coming to an end. What major even...
Speaking of the Communications Design Institute, ...