How do I resolve a ssh connection closed by remote host due to inactivity?

Solution 1:

Add the following to your $HOME/.ssh/config and all your ssh connections will send a TCPKeepAlive every 30 seconds:

TCPKeepAlive yes
ServerAliveInterval 30

Solution 2:

If you are connecting from a Linux computer you can use some options directly from the command line

TCPKeepAlive: This uses the KEEPALIVE option of the TCP/IP protocol to keep a connection alive after a specified interval of inactivity. On most systems, this means 2 hours. So, with the TCPKeepAlive option passed to SSH, the SSH client will send an encrypted packet to the SSH server, keeping your TCP connection up and running.

ssh -o TCPKeepAlive=yes [email protected]

ServerAliveInterval: This sets a timeout interval in seconds, which is specified by you, from which if no packets are sent from the SSH client to the SSH server, SSH will send an encrypted request to the server for a TCP response. To make that request every 30 seconds:

ssh -o ServerAliveInterval=30 [email protected]

Source