scp exec request failed on channel 0

Solution 1:

To see the .bashrc file (and other files beginning with a dot) you need to do

ls -a

The simple workaround is to rename the .profile, .bashrc, .login, .bash_profile files so that they don't get included. These are known as shell startup files.

If your scp now works, the answer lies in one of those files.

Basically one of the shell startup files is sending output back and that messes up the ssl negotiation going on.

It could be as simple as sending special escape sequences to set your window title. Another culprit is the stty command.

You want to surround output to the terminal only when logged in with

if tty -s >/dev/null 2>&1; then
    # here if have a real terminal associated to send stty commands 
    # or other special escape sequences to terminal
fi

Solution 2:

I agree with strobelight that this error is often from output from .bashrc (and other) bash initialization files.

There are some bash-builtin ways to test for interactive shells though: advanced bash-scripting guide reference, serverfault reference.

What I've seen most often is to test $PS1 for when to do output:

if [ "$PS1" ]; then
    echo "some message"
fi