0

I'm running a backup server using rsnapshot, which uses rsync, which uses ssh to connect to the hosts from which to gather data. Usually, everything works fine. I run in to issues, however, if very little data has changed, and if there are a lot of separate directories to be backed up (more than 5). I figured out that the issue is ssh, which can only connect five times within roughly minute, then I have to wait again before making another attempt. This script demonstrates the issue:

#!/usr/bin/bash

for j in {1..3}
do
    for i in {1..6}
    do
        ssh my.server.xyz 'exit' && echo "ok #${i}" || echo "failed #${i}"
    done
    sleep 60
done

The output looks as follows:

ok #1
ok #2
ok #3
ok #4
ok #5
ssh: connect to host my.server.xyz port 22: Connection refused
failed #6
ok #1
ok #2
ok #3
ok #4
ok #5
ssh: connect to host my.server.xyz port 22: Connection refused
failed #6
ok #1
ok #2
ok #3
ok #4
ok #5
ssh: connect to host my.server.xyz port 22: Connection refused
failed #6

Is there some sshd option to configure this limit of 10? I'd like to be able to do up to 10 connections from the same host within a couple of seconds.

3
  • 1
    Connection refused may be because of some firewall or whatever. In SSH there is connection sharing. I guess ssh -M may be a client-side solution. See man 1 ssh. You will also need the -S option of ssh and the -e option of rsync. Alternatively configure your ssh like this, start the first connection manually (ssh -N maybe) and let any number of later connections use it automatically. Untested, therefore just a comment, not a proper answer. If it works for you then feel free to answer your question. Oct 22 at 9:55
  • Thanks Kamil, it really was the Firewall (IP Tables). Oct 22 at 9:59
  • 1
    OK, theoretically if the culprit is like in your answer then my client-side solution should work. It's most useful for people who are not in charge of the firewall. I also noticed this comment which seems to match your case perfectly and removes the need of manual connection. Oct 22 at 10:06
1

I figured out that it has not really anything to do with ssh, but with IP tables on the server (where sshd runs):

# iptables -S | grep 22
-A ufw-user-input -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 30 --hitcount 6 --name DEFAULT --mask 255.255.255.255 --rsource -j ufw-user-limit
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.