Interview Prep/Shell Scripting/Troubleshooting: tools, portability, permissions and environment

`rsync -az ./dist/ deploy@web1:/srv/app/` fails with `protocol version mismatch -- is your shell clean?`, while `ssh deploy@web1` works fine.

AdvancedTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer

Likely causes → rsync speaks its protocol over the SSH channel. Something in the remote user's shell start-up files (~/.bashrc, /etc/bash.bashrc) prints output even for non-interactive shells: an echo "Welcome", a fortune, a version banner. That text corrupts the protocol stream. scp with the legacy protocol fails the same way.

Diagnose →

ssh deploy@web1 /bin/true | od -c | head      # anything printed here is the culprit

Fix → Guard interactive-only output in the remote rc files:

# top of ~/.bashrc
case $- in *i*) ;; *) return ;; esac

Prevent → Keep shell start-up files silent for non-interactive shells, and give automation accounts a minimal, managed .bashrc.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: tools, portability, permissions and environment