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
GigsGigsCloud has launched a new VPS in the Los A...
[[337703]] 【51CTO.com Quick Translation】 The glob...
1. Overview At present, video classification algo...
6G networks are defined as cellular networks that...
As attack and defense exercises become more and m...
On August 9, 2019, Huawei held the "Unleashi...
Hello everyone, I am Zhibeijun. Today, I will lea...
What is Communication? Simply put, communication ...
The network should respond to the needs of users ...
[[426454]] This article is reprinted from the WeC...
Introduction CyberChef is a web application for e...
1. Problem phenomenon A customer reported that in...
[[180048]] Verizon, a US operator, announced that...
Usually, our applications do not need to handle t...
Since 2019, countries have successively issued 5G...