Linux – Troubleshooting why the SSH sessions hang for a couple of seconds

linuxsshtoptroubleshooting

I'm logged in to my development box via SSH (using PuTTY on my laptop) and periodically, the session would just hang for a couple of seconds then becomes responsive again. I have not been able to narrow it down.

Network setup: server and laptop are connected to the same router.

Services on the box:

  • apache
  • CUPS
  • fail2ban
  • mysqld
  • samba
  • sendmail (for SMTP with dkim-filter)
  • SSH (as said before)

top output:

This is from a couple of minutes after the hangup happened.

top - 02:16:14 up 15 days,  1:11,  1 user,  load average: 0.00, 0.03, 0.07
Tasks: 125 total,   1 running, 124 sleeping,   0 stopped,   0 zombie
Cpu(s):  3.3%us,  1.5%sy,  0.0%ni, 92.5%id,  2.6%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:   1017408k total,   950744k used,    66664k free,   359728k buffers
Swap:  4194300k total,    14012k used,  4180288k free,   191344k cached

Tips on figuring this out?

Best Answer

My guess:

SSHv2 clients initiate a key re-exchange after every X minutes and/or Y bytes transferred (in case of PuTTY, the defaults are 60 mins and 1 GB). The rekey should only take 1-3 seconds, but until it finishes no other data can be transferred through the SSH connection.

Look for "Initiating key re-exchange (reason)" in PuTTY's Event Log. (Ctrl Right Click on the terminal window.)

Event Log

If this is indeed the reason, you can:

  • move a specific algorithm (such as DH group 14) above "group exchange" in Connection → SSH → Kex
  • increase the re-exchange timeout in the same page