Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

rsync stops with exit code 12 right after it connects over ssh

Errorrsync error: error in rsync protocol data stream (code 12) at io.c(605)

Short answer

Exit code 12 means the data stream between the two rsync processes broke. Over ssh the usual causes are text printed by the remote shell's startup scripts, which corrupts the protocol, or no rsync program the remote shell can find. Test the shell with ssh host /bin/true; if it prints anything, clean the startup files.

  • Applies to rsync 3.2, OpenSSH 9.x, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run a command that does nothing on the remote side. A clean shell prints nothing at all, so any output is the problem.

    ssh user@remote.example.com /bin/true > out.dat
    wc -c out.dat
  2. 2Match what you see, then jump to its fix

    1. 1protocol version mismatch -- is your shell clean? and out.dat is not emptyThe remote shell prints text when it startsFix
    2. 2The no-op test is clean, but the transfer fails at once with code 12rsync is not in the remote shell's pathFix

What does the error look like?

  • rsync error: error in rsync protocol data stream (code 12) at io.c(605)
  • protocol version mismatch -- is your shell clean?

Cause 1 of 2

The remote shell prints text when it starts

1Check

The rsync manual names incorrectly configured shell startup scripts as the most common cause: anything a login or non-interactive shell echoes lands in the rsync data stream. Look at what the remote account's startup files print.

cat out.dat
ssh user@remote.example.com 'grep -n -E "echo|printf|fortune|neofetch" ~/.bashrc ~/.profile ~/.bash_profile 2>/dev/null'

2Fix

Remove or comment out the lines that print, in the startup file the check found, on the remote host.

# on the remote host: comment out each printing line found above, for example
# echo "Welcome back"

3Verify

The no-op command now produces a zero-length file, and rsync runs.

ssh user@remote.example.com /bin/true > out.dat
wc -c out.dat
rsync -av --dry-run ./site/ user@remote.example.com:/var/www/site/

Confirmed by download.samba.org

Did this fix it?

Cause 2 of 2

rsync is not in the remote shell's path

1Check

The remote shell must be able to start a program called rsync. Ask it where the program is.

ssh user@remote.example.com 'command -v rsync'

2Fix

If rsync is installed outside the default path, tell rsync where to run it with --rsync-path. If it is not installed, install it on the remote host first.

rsync -av --rsync-path=/usr/local/bin/rsync ./site/ user@remote.example.com:/var/www/site/

3Verify

Run the same transfer as a dry run and check it lists files instead of failing.

rsync -av --dry-run --rsync-path=/usr/local/bin/rsync ./site/ user@remote.example.com:/var/www/site/

Confirmed by download.samba.org

Did this fix it?

How do I stop it coming back?

  • Keep shell startup files on servers free of anything that prints.
  • Run the ssh host /bin/true check whenever you add a new server or change a login script.
  • Always rehearse a new transfer with --dry-run (-n).

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.