0

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.

ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
  • Window pops up with "Server unexpectedly closed network connection" – Sridhara Tv Feb 08 '19 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 08 '19 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 08 '19 at 17:58
  • A related, but different, question is https://unix.stackexchange.com/questions/412192/ . – JdeBP Feb 08 '19 at 18:56

2 Answers2

2

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

  • I facing the same issue while using mobile internet(AirTel). My mobile doesn't have the option to switch between LTE and LTE/CDMA. I tried turning off VoLTE, didn't had any effect. – Shiva Nov 12 '19 at 09:36
  • You saved my day, thank you. I swapped from my home wifi to cell phone and it worked. Changing ssh client's or sshd server's configuration (ServerAliveInterval, ClientAliveInterval etc..) didn't solve the problem. – Ferhat S. R. Oct 08 '21 at 00:13
  • I just noticed that, after swapping to my home wifi again, it is also working. Same configuration, weird... – Ferhat S. R. Oct 08 '21 at 00:20
0

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
shelum
  • 36
  • 1
  • 4