I have launched an EC2 instance running ubuntu 16.4 and able to connect using Pytty SSH with Key pair. The issues is even when I'm executing some commands - that is actively working, the session closes every 20 seconds. If I restart the session, I can connect, closes after 20 seconds again. I tried to configure "Seconds between keepalives" to 10 or 20 or any other number, save the session, reopen the connection, I still have the same problem. I also tried to enable TCP_KeepAlives checked, but the problem persists.

I was able to work properly earlier, but I am having the above problem for the past 2 days.

  • Window pops up with "Server unexpectedly closed network connection" – Sridhara Tv Feb 8 at 17:18
  • No. I'm connecting only one session.The last message on the putty log is Event Log: Server unexpectedly closed network connection – Sridhara Tv Feb 8 at 17:41
  • I can reproduce the error you're getting if I manually kill the sshd process that spawns my session. I suspect your remote sshd process(es) are being killed by something. – Jeff Schaller Feb 8 at 17:58
  • A related, but different, question is unix.stackexchange.com/questions/412192 . – JdeBP Feb 8 at 18:56

I had this issue on a AWS Linux AMI instance recently. Should apply to others as well. Changing the server side keep alives worked for me:

  • Edit /etc/ssh/sshd_config
  • Add ClientAliveInterval 120
  • Restart sshd service
  • I tried this option, but the result is the same – Sridhara Tv Feb 10 at 15:47

Finally got the problem fixed. all the while I was using my mobile hotspot to connect. This is 4G connection and I get good internet speed and connectivity. For some reason I had changed the cellular connection type to LTE only on mobile to increase the speed, though it did not really improve the speed, caused this problem. when I reset back to LTE/CDMA which was the preferred network type, all things are fine now.

Thanks to all those who shared their views

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.