rsync stops with exit code 12 right after it connects over ssh
rsync 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.
Fix it fast
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.dat2Match what you see, then jump to its fix
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
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
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
SSH session dies with client_loop: send disconnect: Broken pipe
Broken pipe
By default neither ssh nor sshd sends keepalive messages through the encrypted channel (both intervals default to 0), so a quiet session gives nothing for a firewall or the server to see.
2 causes, each with a fixServers
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 fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix