Reoccurring ssh_exchange_identification: Connection closed by remote host error MacOS (Only fixed by resetting ssh each time)

I am spinning up multiple remote instances via Google Cloud and scp-ing scripts to these instances to run them and get the results scp-ed back to my local computer. Things start smoothly but after a while (about 30 instances later), new instances are unable to scp files back to my computer as I get the error: ssh_exchange_identification: Connection closed by remote host. This error only goes away after I reset my local computer's ssh with the following commands:

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

What is the underlying problem and how can I solve it to have this problem resolved without having to constantly reset my ssh?

1 Answer

You may be running into the sshd MaxStartups limit:

MaxStartups
Specifies the maximum number of concurrent unauthenticated connections to the SSH daemon. Additional connections will be dropped until authentication succeeds or the LoginGraceTime expires for a connection. The default is 10:30:100.
Alternatively, random early drop can be enabled by specifying the three colon separated values start:rate:full (e.g. "10:30:60"). sshd(8) will refuse connection attempts with a probability of rate/100 (30%) if there are currently start (10) unauthenticated connections. The probability increases linearly and all connection attempts are refused if the number of unauthenticated connections reaches full (60).

You could try altering the setting. On MacOS, the configuration file is /private/etc/ssh/sshd_config.

Alternately, you could arrange to stagger the ssh connections into the server, so that they're not all coming in at the same time.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like