The Issue:
SSH connections from a Macbook (Catalina - the SSH Client) to an RPi 4B (Buster, Linux v 4.19.97-v7l+ - the SSH Server) are reliably dropped at random times, but SSH connections from the same Macbook to an Ubuntu Server (18.04 LTS - another SSH Server) are never (hardly ever) dropped. For this reason, I think the cause is the RPi, and not the Macbook, but I am keeping an open mind. I am trying to understand the cause for this, but the primary question here is how to prevent the SSH disconnects.
The error message is always:
client_loop: send disconnect: Broken pipe
The disconnects happen when the Macbook's lid is open, and when it's closed.
The disconnects happen with 3B and 1BP RPis also, but my question is only for the 4B.
Here's the setup:
1. /etc/ssh/sshd_config
for Ubuntu & RPi are virtually identical; diffs are:
For the Ubuntu Server:
# $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $
Line 96: #UseLogin no
Line 123: PasswordAuthentication yes
For RPi 4B, sshd_config is default (as I found it) :
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
2. Login/Authentication:
- Ubuntu logins are done w/ userid & password;
- RPi logins are done w/ stored SSH credentials.
3. Network Connection & Provisioning:
- Both RPI and Ubuntu are connected to the LAN via Ethernet.
- Ubuntu Server has a fixed IP, RPi 4B uses DHCP.
- Macbook connects to the same LAN as the servers, uses same DHCP server, but is connected via WiFi
4. SSH versions:
Macbook:
% ssh -V OpenSSH_8.1p1, LibreSSL 2.7.3
Ubuntu:
$ ssh -V OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
Raspberry Pi 4B:
$ ssh -V OpenSSH_7.9p1 Raspbian-10+deb10u2, OpenSSL 1.1.1d 10 Sep 2019
5. Keep-Alive Arrangements:
I've tried numerous settings on both the client-side (ssh), and the server-side (sshd). The results have been the same: RPi connections reliably drop at random times, Ubuntu Server connections never (hardly ever) drop. I finally decided to use default /etc/ssh/sshd_config
files on all SSH servers, and deal with Keep-Alive in the (Macbook) SSH client. Here's what I've got now:
% cat .ssh/config
Host *
UseKeychain yes
AddKeysToAgent yes
ServerAliveInterval 120
ServerAliveInterval
Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.
As of 2021-04-25, the Mac's client configuration at ~/.ssh/config
is:
Host *
UseKeychain yes
AddKeysToAgent yes
ServerAliveInterval 6000
ServerAliveCountMax 240
TCPKeepAlive no
6. Is it a Power Issue?
I don't think it's a power issue as discussed here for three (3) reasons:
I'm using a 5V, 3A USB-C Power Supply mfd by Apple w/ a non-eMarked cable.
The Power Supply is plugged into a massive UPS that's lightly loaded. The UPS log shows no issues for weeks on end.
I have 2 other Raspberry Pis: a 1BP (buster), and a 3B (stretch) that reliably but randomly drop SSH connections just as the 4B does.
7. Is it a Macbook Issue?
Obviously I don't think so, or I'd post the question somewhere else. If the Macbook sits for a while, the connection will drop
But those of you familiar with Apple's myriad schemes for power saving may suspect that is the most likely cause. I thought so too initially, but as I've experimented w/ this, I've come to feel it's more likely a Raspberry Pi issue. ICYI, a s/s of the Macbook (SSH Client) Power Management settings is shown below. There's also a power management mode called standby that has been disabled (i.e. never go into standby) and confirmed as follows:
% sudo pmset -a standby 0
% pmset -g | grep standby
standbydelaylow 10800
standby 0 # no standby confirmed
standbydelayhigh 86400
highstandbythreshold 50
pmset
, but documentation is poor. In fact, it's difficult to tell what happens in any of these modes - seems Apple changes them at their whim & can't be bothered to document anything. (Yes, I am currently unhappy with several of Apple's decisions.)ssh -vvv -o ServerAliveInterval=30 pi@<raspi-ip>
. There you have extended logging (-vvv) and a simple way to fiddle with ServerAliveInterval. I think the disconnect error message is from the client when the server cuts the session.