Putty: 'Server unexpectedly closed network connection'

11

4

Putty 'Server unexpectedly closed network connection' I have been getting the 'Server unexpectedly closed network connection' (see https://superuser.com/questions/735824/putty-ends-to-an-unexpected-error-and-vnc-shows-terminal-with-error and Getting “Server unexpectedly closed network connection”) but it is not associated with any reboot, the connection just fails unexpectedly and with it, the web server (Apache) running off the Linux server. I use Putty through Windows 7 to connect to a Raspberry Pi running Raspbian. Any ideas what might be going wrong?

Grant_Bailey

Posted 2014-10-15T05:48:28.207

Reputation: 121

Answers

13

A PuTTY session left idle will disconnect at a time determined by the host server. Try enabling keep-alives in PuTTY. This causes PuTTY to send null SSH packets to the remote host periodically, preventing the session from timing out.

The PuTTY client can be configured to always establish a connection which will not time out due to inactivity. To create and save a new keep-alive connection, follow these steps:

  1. Open the PuTTY application, and go to the Options panel (labeled "Category") on the left of the window.
  2. Select (click) the "Connection" item.
  3. In the ​​"Sending of null packets to keep the session active" area on the right, change the default value of "Seconds between keepalives" from 0 (turn off) to 1800 (30 minutes).
  4. Select the "Enable TCP keepalives (SO_KEEPALIVE option)" check box. Note: This option may not be available in older versions of the PuTTY client.
  5. On the topmost left side of the Options panel, select (click) "Session".
  6. In the "Host Name (or IP Address)" field, enter the destination host name or IP address (e.g., "destination.ipaddress.here.com" or "192.168.1.1").
  7. In the "Saved Sessions" text-entry box, provide a name for the session (e.g., "savedsession").
  8. Select "Save".

To use the modified session settings, select it from the "Saved sessions" list, then click the buttons marked "Load" and "Open".

If your connected sessions still time out, enter a lower number of seconds into the "Seconds between keepalives" value.

afrab_null

Posted 2014-10-15T05:48:28.207

Reputation: 146

This, as well, is incorrect. A TCP connection does not, ever, time out. If the end-to-end principle is undermined by NAT or the like, the connection mappings on these devices might time out. SSH will, by default, never time out. On a proper internet connection, an idle SSH connection will remain open indefinitely. – Daniel B – 2014-10-15T07:31:07.530

Ssh offers two kinds of keep-alives: TCP keep-alives and ssh keep-alives. TCP does offer a mechanism to automatically close connections deemed dead because of timeout. It is about activating a flag in the socket. – Raúl Salinas-Monteagudo – 2014-10-16T08:45:53.903

I have been lowering the number and am back at 0 and still won't work. Is there a a different solution to this? – myselfmiqdad – 2018-07-18T15:02:13.597

1

The server could have been hardened. The reason could be a) the client ip may be not configured in /etc/allowhosts and/or b) unix/linux firewall rule/selinux is not permitting.

AVA

Posted 2014-10-15T05:48:28.207

Reputation: 115

0

I had the same problem for a long time, I use putty to connect to AWS linux instances (some remote cloud servers) I read about fixing it with keepAlives in several pages several pages, tried it but to no avail.

And just yesterday, while looking for some color scheme settings I found this: https://github.com/jblaine/solarized-and-modern-putty

Besides adjusting the colors of the terminal it does apply some sane defaults (Like the forementioned KeepAlives to 59 seconds plus others), and guess what? I havent had any closed connection for two whole days.

Mario Chapa

Posted 2014-10-15T05:48:28.207

Reputation: 111

-1

You were idle longer than the session timeout on the remote device, so it closed the session and PuTTy wasn't expecting it.

cpt_fink

Posted 2014-10-15T05:48:28.207

Reputation: 377

1Not exactly, though: If you log out (or are forcefully logged out), the connection is terminated gracefully. What happened here is that the underlying TCP connection was somehow closed (“Connection reset by peer”), hence “unexpectedly”. – Daniel B – 2014-10-15T07:17:10.333

Where do you see "reset"? To me the obvious meaning of "unexpectedly closed" is TCP-close not expected at SSH level, and testing confirms this: if I exit from or kill my shell I get serveral SSH packets (I ass-u-me CHANNEL_EOF, CHANNEL_CLOSED and/or DISCONNECT) then FIN exchange and Putty pops "closed by remoted host"; OTOH if I kill -9 my sshd I get only TCP FIN exchange and "server unexpected closed network connection". If it was RST (and not at SYN where it means refused) I would suspect some middlebox, consistent with your other comment. – dave_thompson_085 – 2014-10-15T08:41:53.583

@dave_thompson_085 You’re right, I confused FIN and RST. Otherwise, KiTTY says “Software caused connection abort”. – Daniel B – 2014-10-15T18:38:54.740