Raspberry Pi SSH Lag
Yesterday I got my Raspberry Pi B+, which I use via SSH. Sometimes the SSH typing takes about 5s and more to respond with an visual feedback after a time of idleness, after that lag everything just works fine.
(I started typing the moment the gif starts.)
I know the Raspberry Pi is no super modern MacBook Pro, but it's still kind of strange. I checked the connection, and checked my terminal setting, tried reconnecting with the pi and checked if other servers I use respond similar, but everything works fine with other servers. Could anybody tell me if they have the same problem and if so how to solve it?
Solution 1:
It seems the OP has already found the solution. This answer is for future reference.
The OP's comment:
It turned out to be
ClientAliveInterval
of the openSSH server. That solved it.
The comment gives no further details. Fortunately quick Google search led to a post on www.raspberrypi.org
:
by TimKaechele » Mon Sep 01, 2014
You can solve the problem in two ways:
- setting the
ServerAliveInterval
to a number of seconds less than the time it takes to time out the connection,- or by configuring the SSH server's
ClientAliveInterval
(same process).
Solution 2:
Is your PI running the stock raspbian image? If not please check following things:
- Is your PI under heavy load? Check with
uptime
.
05:06:50 up 7 days, 17:49, 1 user, load average: 0.00, 0.01, 0.05
- Does the PI behaves the same if you log in locally using monitor / keyboard.
- Does the PI behaves the same if you use another machine to ssh from?
- Is your network under heavy load and running slow?
Your problem seems to be unrelated to coding in general. Maybe ask this question in another community like Super User
Solution 3:
I also suffered this issue for about a week until i finally figure out this is not caused by any setting of any config files. The true reason cause this laggy SSH connection is due to Raspberry Pi's poor BCM2837/43438 WiFi Bluetooth chip design , they share single antenna.
So please check if you have any Bluetooth device paired with your pi, even those device are powered OFF, remove all of them form paired device list, then your SSH is back to normal.
Solution 4:
I encountered the same issue with Fedora Server 33 on a Raspberry Pi 4, the symptoms were :
- Laggy SSH connection after leaving it untouched just a few seconds (just like the video above)
- Pings to another host were all over the place, ranging from 20ms to 300ms
It was caused by the power management of the Wifi card. After disabling it everything went back to normal :
# Raspberry Pi OS arm64
iwconfig wlan0 power off
# Fedora 33
mcli connection modify wlan0 wifi.powersave disable
More reference on how to disable Wifi power management depending on your setup : https://askubuntu.com/questions/695867/disable-wifi-power-management