Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

rsync "protocol version mismatch -- is your shell clean?": find what writes to the connection before rsync starts

Technical article
Backup & Recovery

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

rsync prints protocol version mismatch -- is your shell clean? followed by (see the rsync manpage for an explanation) and exits with code 2, "Protocol incompatibility". The rsync manual says this is the message that "seems to cause the most confusion", and that it is usually caused by startup scripts or the remote shell producing unwanted garbage on the stream rsync uses for its transport. The test it gives is to run the remote shell with /bin/true into a file; the file should be empty.

What the message means

rsync over a remote shell talks over the shell's standard input and output. In rsync 3.3.0 and 3.4.1, the function setup_protocol in compat.c writes rsync's own protocol version, then reads four bytes from the other side with read_int and treats them as the peer's protocol version. The byte order is little-endian: the first byte is the lowest part of the number.

If that number is below MIN_PROTOCOL_VERSION or above MAX_PROTOCOL_VERSION, rsync prints the two lines above and exits with RERR_PROTOCOL, which errcode.h defines as 2. In rsync 3.3.0 and 3.4.1, rsync.h sets the minimum at 20 and the maximum at 40; rsync's own version is 31 in 3.3.0 and 32 in 3.4.1. Anything that arrives before the peer's rsync writes its version, such as a greeting echoed by a login script, becomes the "version".

This is a reading of the code, not a statement in the manual. The manual's own words are the cause in the paragraph above.

Likely causes

Cause What you see How to confirm
A startup script prints text for non-interactive logins The error on every run to that host ssh remotehost /bin/true > out.dat leaves a file that is not empty; the manual names .cshrc and .profile
Another remote shell facility prints text The same, and the startup files look clean The same test; the manual says "startup scripts or remote shell facility"
A program given with --rsync-path prints text Only jobs that use --rsync-path fail Run the job without it, or run the program by hand
The other side speaks a protocol version outside 20 to 40 A real mismatch, rare rsync --version on both ends; the manual describes --version as printing the version and other information

Prove the cause before changing anything

All steps read only. Replace backup@app.example.com with the account and host from the failing job.

1. Run the remote shell as rsync does. The manual's test, with /bin/true as the remote command:

ssh backup@app.example.com /bin/true > out.dat

Then look at the file. Its size should be zero:

wc -c out.dat

A good result is 0. Any other number means something wrote to the connection; print the first bytes to see what, for example with head -c 200 out.dat. The manual says: "Look at the contents and try to work out what is producing it."

2. Use the same user and options as the failing job. Startup scripts depend on the account, and an interactive login can look clean while a non-interactive one prints text. If the job uses --rsh (-e), which the manual describes as specifying the remote shell to use, or --rsync-path, test with the same remote shell and the same program. A job started by cron or a scheduler runs as its own account, so test as that account.

3. Compare versions. Run this on both ends and compare the lines it prints:

rsync --version

Fix

A startup script or shell facility prints output

The manual says the most common cause is "incorrectly configured shell startup scripts (such as .cshrc or .profile) that contain output statements for non-interactive logins." The fix is to stop output for non-interactive logins. Find the script on the remote host for the account the job uses; the manual names .cshrc and .profile as examples, and which file is read depends on the remote shell. Our advice, not rsync's: keep greetings for interactive terminals only, for example with a test that standard output is a terminal.

Replace ~/.profile in the next commands with the file you found. First save the current state, on the remote host as the job's account:

cp -p ~/.profile ~/.profile.2026-12-02

Risk: the next edit changes the login startup script of the account the backup uses, and a mistake in it affects every login by that account, interactive logins included. Keep a second login session open until the test passes.

Edit the script so the output statement runs only when output goes to a terminal. In a POSIX shell script, change echo "Welcome to app.example.com" to:

if [ -t 1 ]; then echo "Welcome to app.example.com"; fi

To undo it: restore the saved copy under its saved name (use the same file you replaced ~/.profile with above), then repeat the test from step 1.

cp -p ~/.profile.2026-12-02 ~/.profile

If the greeting comes from a file the startup script reads, such as a message of the day, move the output statement the same way. Repeat ssh backup@app.example.com /bin/true > out.dat and check wc -c out.dat shows 0.

A program given with --rsync-path prints output

The manual says the program is run with the help of a shell, so it can be any program, script or command sequence, "so long as it does not corrupt the standard-in & standard-out that rsync is using to communicate." A wrapper that prints on standard output before rsync starts breaks that condition. The wrapper is a program the job depends on; correcting it is a change to plan separately, with its own saved copy of the wrapper, and is not covered by the commands here.

The versions really are incompatible

If the first bytes of out.dat are empty and the failure remains, compare the two rsync --version outputs. A peer that reports a protocol version below 20 or above 40 gives the mismatch message. Separately, for versions below 25 rsync prints a notice, Server is very old version of rsync, upgrade recommended. or Client is very old version of rsync, upgrade recommended., and carries on. So an old rsync on one side is a cause only if it is below 20; upgrading it is a change to plan separately and is not covered by the commands here. The manual describes --protocol=NUM as forcing an older protocol, mainly for batch files; it does not describe it as a fix for this message.

Example (illustrative): the nightly job rsync -a /srv/data/ backup@app.example.com:/backup/data/ fails with the message. ssh backup@app.example.com /bin/true > out.dat then wc -c out.dat shows 27, and the file holds Welcome to app.example.com and a newline (26 characters + 1 = 27 bytes). The first four bytes are the letters W, e, l, c: 87, 101, 108 and 99. Read little-endian, that is 87 + 101 × 256 + 108 × 65,536 + 99 × 16,777,216 = 1,668,048,215, far above the maximum of 40. The administrator guards the echo in ~/.profile (the manual names .profile and .cshrc; which file is read depends on the remote shell), the file size becomes 0, and the job runs.

Confirm the fix

  1. wc -c out.dat shows 0 for the same user and host.
  2. A dry run with -n completes without the message. Replace the paths with your own: rsync -avn /srv/data/ backup@app.example.com:/backup/data/
  3. The real job runs and exits with code 0; see rsync error code 23 and 24 in backup jobs: partial transfer, vanished files and when to treat them as failure for exit codes 23 and 24.

What to watch afterwards

Risks and limits

  • These commands have not been run or lab-tested.
  • The rsync manual gives startup scripts and the remote shell facility as the usual causes; it does not list every source of output.
  • The byte-level explanation is a reading of the source code at the tags named, not a vendor statement; later versions may differ.
  • The [ -t 1 ] guard is our own advice and suits POSIX shells; .cshrc uses different syntax.
  • Editing a login script can lock out or confuse logins; keep a second session open while you test.

Sources

  • rsync.1.md (manual page source) — RsyncProject/rsync repository, tag v3.3.0, no date shown, accessed 2 December 2026
  • compat.c — RsyncProject/rsync repository, tag v3.3.0, no date shown, accessed 2 December 2026
  • compat.c — RsyncProject/rsync repository, tag v3.4.1, no date shown, accessed 2 December 2026
  • rsync.h — RsyncProject/rsync repository, tag v3.3.0, no date shown, accessed 2 December 2026
  • rsync.h — RsyncProject/rsync repository, tag v3.4.1, no date shown, accessed 2 December 2026
  • errcode.h — RsyncProject/rsync repository, tag v3.3.0, no date shown, accessed 2 December 2026
  • io.c — RsyncProject/rsync repository, tag v3.3.0, no date shown, accessed 2 December 2026
  • byteorder.h — RsyncProject/rsync repository, tag v3.3.0, no date shown, accessed 2 December 2026