Solution 1: The server actively keeps the connection
Log in to the server and open the ssh configuration file
vim /etc/ssh/sshd_config
Add the following statement
ClientAliveInterval 120
ClientAliveCountMax 720
Restart sshd
service
systemctl restart sshd
- The first sentence means that the server will send an empty packet to the client every 120s.
- The second sentence indicates that the server will send a maximum of 720 times, 120*720=24 hours
- The connection will not be disconnected during 24 hours
Solution 2: The client actively keeps the connection
Edit ~/.ssh/config
files, increasingServerAliveInterval 120
Host server
HostName xxx.domain.local
ServerAliveInterval 120
User root
Send an empty packet to the server every 120 seconds
Reprinted from: SSH keeps connected