[SOLVED] SSH connection sometimes hangs

I’m experiencing some ssh lockups / freeze when using Putty to connect to my Raspberry pi 3 B+. The lockups seems to happen at random, but the network connection is active: for example, I can open a cmd shell on my laptop and ping -t the Raspberry with no packet loss and, furthermore, I can browse/read/write files on the /home/osmc directory using Windows SMB without errors. So I think the problem maybe a ssh server on the Raspberry (or putty) misconfiguration, but I wasn’t able to rule it out. Ah, when I try to reconnect using Putty, I’m getting the image below:


After a long time (minutes!!) sometimes I can log in, sometimes I can’t. Very odd behavior.

Here is my configuration:

  • Raspberry pi 3 B+ with original 2.5 A power supply;
  • microSD Samsung Evo plus 128GB (genuine);
  • 2 TB HDD directly connected to the onboard USB;
  • Logitech KT400 wireless keyboard (connected via its USB dongle).


  • OSMC latest vesion (image OSMC_TGT_rbp2_20181101.img.gz);
  • Retropie installed on the microSD (using the retrosmc script).


  • Raspberry connected to my Wifi network (2.4 GHz) using the onboard wifi;
  • static IP address, Gateway
  • SSH client: Putty on Windows 10 64 bit.

My logs:

Any advice /suggestion to solve this annoying ssh problem?
Except of this problerm OSMC (plus Retropie) works very well :slightly_smiling_face:

Cheers, Kranz

It may be caused by powersaving on the internal adapter

Thank you.
I’ll try to disable power management via iwconfig and see if it solves.

Bye, Kranz

I have disabled Wifi power management (adding sudo iwconfig wlan0 power off in rc.local) but the SSH freezes/disconnections still remain. I’ve also checked power management status:

osmc@osmc:~$ iwconfig
eth0      no wireless extensions.

wlan0     IEEE 802.11  ESSID:"ODPEGOF"
      Mode:Managed  Frequency:2.412 GHz  Access Point: 30:91:8F:7C:2B:BD
      Bit Rate=65 Mb/s   Tx-Power=31 dBm
      Retry short limit:7   RTS thr:off   Fragment thr:off
      Power Management:off
      Link Quality=62/70  Signal level=-48 dBm
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:0   Missed beacon:0
lo        no wireless extensions.

so I’m sure that is effectively disabled.
I’m able to ping the raspberry even when experiencing SSH freezes and samba shares are accessible and files (in my /home/osmc or in /media) are readable & writable. Only SSH connections have problems.

What else can I do to track down this problem?


I’d check your power supply.

adding the following line at the end of /etc/ssh/sshd_config

IPQoS cs0 cs0

ruled out my freeze/disconnection SSH problems :slight_smile:

Edit: explaination of the problem:
OpenSSH sets the TOS (type Of Service) field in the IP datagram as “lowdelay” for interactive sessions and “throughput” for non-interactive sessions. My router doesn’t handle properly those settings, so I changed them in Cs0, Cs0 (aka 0x00, 0x00) <==> (best effort, best effort) and solved the instability/freeze SSH issues.
sshd_config(5) man page
Differentiated services
I’ll mark this post as solved after some days of testing.

Thank you, Kranz

This worked for me! Pi Zero W , all ssh i made ( putty from windows, raspcontrol from android) had intermittend connection failures. Adding this line to the sshd_config solved this issue

That is indeed interesting and potentially useful!

Never the less, mid the simple and stupid causes as well. Just yesterday I realized I cannot ssh into my Pi nor access its apache, although all was looking good in the router and from the X on RasPi. Guess what, I tried to go back with the recent terminal commands … to find out that I had set up the gufw firewall (just fooling around to see what it actually can do) and cut off both the posr 22 and inbound port 80 on both the Pi and my desktop. :smiley: