0

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 1

0

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
  • But when I create these instances, I am also giving them a RSA key to be able to access my computer for scp-ing. So would these connections be considered unauthenticated?
    – Nole
    Commented Aug 8, 2018 at 15:48
  • Every connection is unauthenticated until it authenticates.
    – Kenster
    Commented Aug 8, 2018 at 15:56
  • OK I have changed MaxStartups to 200 and MaxSessions to 500, and restarted my ssh process but I am still running into this problem. When does the sshd's limitation reset? I have found that if I wait a couple hours the problem also goes away.
    – Nole
    Commented Aug 9, 2018 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .