Your post does not contain information why the connection timeout happens. If the server terminates the connection because the client was silent for too long, you can set the ServerAliveInterval (assuming you are using OpenSSH).
From the man page
Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.
The configuration for this goes into $HOME/.ssh/config
on the client. If you want to send the signal every minute to the remote host example.net, put the following in the configuration file:
Host example.net
HostName example.net
ServerAliveInterval 60
You can enable it for all host if you use a wildcard
Host *
ServerAliveInterval 60
You can set a similar option on the server side in /etc/ssh/sshd_config
. It is called ClientAliveInterval. This could be helpful if you run the server yourself and don't want to customize all your clients.
From the man page
Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.