I experienced this strange behavior with rsync command:

sudo rsync --timeout=300 --compress-level=9 -aHe "ssh -o ConnectTimeout=200 -o ServerAliveInterval=2 -ServerAliveCountMax=200" --progress --delete -z /media/Restic/* [email protected]:/DataVolume/BACKUPS/T4-Ubuntu-Restic

After few minutes, I get the error

rsync: [sender] write error: Broken pipe (32)

I tested with another concurrent ssh session in second terminal window running ping to gateway and it keeps running even when rsync breaks, it just pauses for a while when rsync breaks. It seems to me that Ubuntu kills the connection for a second or two and then resumes.

I wonder why ssh on rsync reports broken pipe immediately and does not wait for timeout 200 or 300 that I have set up in the command.

  • 1
    You are missing -o before -ServerAliveCountMax. Is this just a copying error?
    – meuh
    Commented Apr 4, 2019 at 12:44

2 Answers 2


The --bwlimit=4096 option solved it for me


The --timeout option is used to handle situations where the remote rsync has hung or otherwise become unavailable. It means "wait for this many seconds before giving up on the remote connection".

If the connection is forcibly closed, as in your scenario, there is no longer any connection and rsync can no longer communicate with its peer. Since it can now guarantee it will never hear from its peer it gives up and reports an error to you immediately.

Ideally you should investigate why your server is closing connections indiscriminately. In the meantime putting a loop around the transfer process may help

while :
    rsync ... /media/Restic/ [email protected]:/DataVolume/BACKUPS/T4-Ubuntu-Restic &&

    [[ -t 2 ]] && echo "Rsync failed with status $ss; retrying..." >&2
    sleep 60
  • Thanks for suggestion. I was thinking of this solution, but I first need to set up ssh root on NAS for key-only authentication. I can only use root user, so I am a bit struggling, because tutorials suggest to turn off password for root completely which I can not do. I need that root can be authenticated by password OR a key, not by key only.
    – Jan
    Commented Apr 4, 2019 at 13:58
  • @Jan if you want password and your destination username is root you need first to disable the "disallow root" setting in /etc/ssh/sshd_config and then set a password for the account. To enable the key, take your source user's id_rsa.pub file and append its one-line contents to the destination user's file .ssh/authorized_keys (create the file if necessary). Commented Apr 4, 2019 at 18:53

You must log in to answer this question.

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