2

At home I have a 2017 iMac running Big Sur and a couple of Raspberry Pi 4s on Buster. At my condo I have a 2010 MacBook and two more Pi 4s on Buster. The machines at the condo are behind a double NAT. Each one of them establishes a reverse SSH tunnel to the iMac so I can log into them from home. Normally, this works fine. When I'm at the condo I'm able to log into the iMac at home directly (no tunnel required). Normally, this works fine.

Sometimes it fails. For example, here I try to log in to the home iMac from the old MacBook at the condo:

Whitey:~ mnewman$ ssh -p 10000 [email protected]

ssh: connect to host xxxx.myddns.rocks port 10000: Operation timed out

I connect to the iMac via VNC, start a terminal session and restart the daemon:

sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Then the remote ssh works fine:

Whitey:~ mnewman$ ssh -p 10000 [email protected]
Last login: Thu Dec 30 17:25:54 2021
MrMuscle:~ mnewman$

Same thing happens when logging in from the home iMac to the remote Pies. Restarting the daemon always gets things running again.

What can I do to avoid having to restart the ssh daemon?

6
  • This is a great question :) I am still looking for an answer to a potentially related problem, so please drop me a line if you find it here.
    – Seamus
    Commented Jan 3, 2022 at 1:59
  • @Seamus The bottom line is that ssh seems to be unreliable in recent MacOS versions. In my case, it appears that launchd simply stops listening on port 22 which results in a timeout for incoming requests. The only way I've found to goad launchd in to paying attention is to unload/load the Launch Daemon plist. I shouldn't have to do that. - But I've also seen the "broken pipe" error that you describe. I figured that must be a Mac mistake because sessions between Pies never fail that way. I'm irked because ssh should be something that reliably "just works". It does not.
    – Buadhai
    Commented Jan 4, 2022 at 0:00
  • I figure it's the Mac also, but difficult to rule out sshd on the Pi without a smoking gun. I lost my motivation for troubleshooting when the problem seemed to "go away" for a while, but it's come back & been consistent for quite some time now. And being honest, I don't feel I know this well enough to figure it out in any sort of a reasonable time frame. I'd love to see the OpenSSH team tackle this :) I wonder though - would they cast it aside as an "Off Topic" question?
    – Seamus
    Commented Jan 4, 2022 at 5:41
  • @Seamus I understand. I've had the problem I describe here for a long time. I make a stab at it now and then but don't make much progress. As I understand it, the MacOS only runs the ssh daemon when a request is made on port 22. Launchd listens on that port and if a request is detected it loads /System/Library/LaunchDaemons/ssh.plist which runs /usr/sbin/sshd. Perhaps this is why the OpenSSH group doesn't want to deal with it. On linux systems sshd runs at boot time and listens for connections. I've had fewer broken pipe woes since setting ServerAliveInterval 300 in ~/.ssh/config on my Mac.
    – Buadhai
    Commented Jan 4, 2022 at 9:29
  • In my case, only the SSH client runs on macOS; the SSH daemon runs on the RPi - a consequence of running my RPis "headless".
    – Seamus
    Commented Jan 4, 2022 at 9:59

0

You must log in to answer this question.

Browse other questions tagged .