In case your ssh connection is permanently disconnected in idle state, you can enable TCP-Keepalive either on the ssh server or the client or on both.

To enable TCP-Keepalive on the ssh server, you can comment out the following line in /etc/ssh/sshd_config

TCPKeepAlive yes

To enable TCP-Keepalive on the Linux client system wide, you can edit the /etc/ssh/ssh_config file and add the following entry

ServerAliveInterval 15

15 -> timeout interval in seconds after which if no data has been received from the server, ssh will send a message through the encrypted channel to request a response from the server.

If you want to enable this only for a specific user, you can add the following lines into the user’s ssh config file located in /home/<username>/.ssh/config or only for the actual user by ~/.ssh/config.

If the config file doesn’t exists, simply create it.

Host *
ServerAliveInterval 15

To enable TCP-Keepalive on the client (Putty), you can check Enable TCP keepalives (SO_KEEPALIVE option) as follows and further set the seconds to send null packets to the server to keep the session active.

For WinSCP use the following settings in Advanced for the specific ssh connection.

Sending of null SSH packets