Some network routers and firewalls need to keep track of all connections through them. Usually, these firewalls will assume a connection is dead if no data is transferred in either direction after a certain time interval. This can cause PuTTY sessions to be unexpectedly closed by the firewall if no traffic is seen in the session for some time.
To solve this issue, you can configure PuTTY to send null packets and TCP keepalives every few seconds.
In the left-hand menu pane, select Connection
In the field beside Seconds between keepalives, enter 5.
Check Enable TCP Keepalives (SO_KEEPALIVE option)
Now click Open and leave the SSH connection idle for a while to see if it stays up. If you are using a PuTTY session profile, don’t forget to Save your profile with these new settings.
I’m Still Getting Disconnected!
Keepalives are not always helpful..
Keepalives help if you have a firewall which drops your connection after an idle period; but if the network between you and the server suffers from breaks in connectivity then keepalives can actually make things worse. If a session is idle, and connectivity is temporarily lost between the endpoints, but the connectivity is restored before either side tries to send anything, then there will be no problem – neither endpoint will notice that anything was wrong.
However, if one side does send something during the break, it will repeatedly try to re-send, and eventually give up and abandon the connection. Then when connectivity is restored, the other side will find that the first side doesn’t believe there is an open connection any more.
Keepalives can make this sort of problem worse, because they increase the probability that PuTTY will attempt to send data during a break in connectivity. (Other types of periodic network activity can cause this behaviour; in particular, SSH-2 re-keys can have this effect. Therefore, you might find that keepalives help connection loss, or you might find they make it worse, depending on what kind of network problems you have between you and the server.
Check for unreliable Internet connection
The problem may be an unreliable Internet connection. Monitoring your pings is a good way of determining if your connection is dropping packets and is to blame for PuTTY disconnecting.
Open Windows Command Prompt and run
ping google.com -t (or the IP address of your remote server) and leave it running while you SSH connection is open. If you see even one Request timed out, this indicates a connectivity issue and may cause PuTTY to disconnect.
You can also try some software that tests the uptime of an Internet connection. See: Internet Connectivity Monitor.
Try a different SSH client
Try using a different SSH client like (http://kitty.9bis.net) and see if the problem happens on that as well. If it does, you can isolate the problem away from PuTTY.
p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.