2

I have a script with many rsync commands that I use to partially synchronize certain file types in certain directories across two machines. Both have Ubuntu.

The first few tens of rsync commands run smoothly, but then I get the errors:

rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
ssh_exchange_identification: read: Connection reset by peer
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(235) [Receiver=3.1.2]
ssh_exchange_identification: read: Connection reset by peer
...

The problem seems to be due to having many ssh transfers in a short time window. Actually, if I put a few sleep 60 commands, once every 10 rsync commands or so, the script runs flawlessly.

Does anyone know what could be causing this? I tried to change some of the settings in /etc/ssh/sshd_config in both machines (MaxStartups MaxAuthTries and MaxSessions), but the issue persists. I think that none of those should be relevant for this issue; for example, MaxStartups limits the number of unauthenticated ssh connections established at the same time, but my script includes a list of rsync commands that are run sequentially (each session is closed before the next one opens). I couldn't find any setting that limits the number of ssh connections in a time window.

/var/log/auth.log doesn't seem to include any useful info (just showing the output corresponding to the last successful connection and the first few unsuccessful ones; IP and other personal info are masked):

Oct 15 15:58:15 localhostname systemd-logind[773]: New session 152 of user username.
Oct 15 15:58:25 localhostname sshd[31252]: Received disconnect from xxx.xxx.xxx.xxx port 2709:11: disconnected by user
Oct 15 15:58:25 localhostname sshd[31252]: Disconnected from user username xxx.xxx.xxx.xxx port 2709
Oct 15 15:58:25 localhostname sshd[31199]: pam_unix(sshd:session): session closed for user username
Oct 15 15:58:25 localhostname systemd-logind[773]: Session 152 logged out. Waiting for processes to exit.
Oct 15 15:58:25 localhostname systemd-logind[773]: Removed session 152.
Oct 15 15:58:25 localhostname sshd[31255]: Connection reset by xxx.xxx.xxx.xxx port 12951 [preauth]
Oct 15 15:58:25 localhostname sshd[31257]: Connection reset by xxx.xxx.xxx.xxx port 35552 [preauth]
Oct 15 15:58:25 localhostname sshd[31259]: Connection reset by xxx.xxx.xxx.xxx port 60391 [preauth]

Many thanks for any feedback,

3
  • Wondering if you ever resolved this or pinned down the cause. I've started to experience the same thing with scripted rsyncs. May 16, 2022 at 12:20
  • it was because of a network configuration limiting the number of ssh connections, as Kenster suggested. I solved it by enabling multiplexing with control master as indicated in link link
    – fbaroni
    May 17, 2022 at 13:18
  • thanks! It doesn't seem I was opening multiple connections but in one test at any rate multiplexing with control master fixed the problem. May 17, 2022 at 20:26

1 Answer 1

2

It appears that the TCP connection from the client to the server is being reset immediately after it's created, and both the client and the server are reporting that the connection was reset by the other party.

Under these circumstances I'd suspect that a firewall or some kind of malware/intrusion detection software is interfering with these TCP connections. If it only happens when opening several connections during a short period of time, it may be a form rate limiting, or that could be the kind of behavior that the protection software is looking for.

1
  • Thank you @Kenster. I think that neither machine has any firewall running (if I run sudo ufw status it shows: Status: inactive). Maybe my institution has some network restriction that might be causing this, I will ask.
    – fbaroni
    Oct 15, 2021 at 15:48

You must log in to answer this question.

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