I've been experiencing very strange behavior of SCP for some time: whenever I try to copy a file, the output of SCP contains a bunch of underscores and the file is not copied.$ scp test.txt 192.168.0.2:~job@192.168.0.2's password:  ________________________________________When I create an SSH connection using Midnight Commander and copy files it does work.Some info about my machine:$ ssh -VOpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010$ uname -aLinux squatpc 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:05:41 UTC 2011 i686 i686 i386 GNU/LinuxAnd I'm running Kubuntu 11.04.Edit: Some more info as requested by the comments:$ scp -v test.txt 192.168.0.2:~Executing: program /usr/bin/ssh host 192.168.0.2, user (unspecified), command scp -v -t -- ~OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010debug1: Reading configuration data /etc/ssh/ssh_configdebug1: Applying options for *debug1: Connecting to 192.168.0.2 [192.168.0.2] port 22.debug1: Connection established.debug1: identity file /home/job/.ssh/id_rsa type 1debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048debug1: identity file /home/job/.ssh/id_rsa-cert type -1debug1: identity file /home/job/.ssh/id_dsa type -1debug1: identity file /home/job/.ssh/id_dsa-cert type -1debug1: identity file /home/job/.ssh/id_ecdsa type -1debug1: identity file /home/job/.ssh/id_ecdsa-cert type -1debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1 Debian-1ubuntu3debug1: match: OpenSSH_5.8p1 Debian-1ubuntu3 pat OpenSSH*debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-1ubuntu3debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: server->client aes128-ctr hmac-md5 nonedebug1: kex: client->server aes128-ctr hmac-md5 nonedebug1: sending SSH2_MSG_KEX_ECDH_INITdebug1: expecting SSH2_MSG_KEX_ECDH_REPLYdebug1: Server host key: ECDSA 28:f3:2b:31:36:43:9b:07:d8:33:ca:43:4f:ca:6c:4cdebug1: Host '192.168.0.2' is known and matches the ECDSA host key.debug1: Found key in /home/job/.ssh/known_hosts:20debug1: ssh_ecdsa_verify: signature correctdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: Roaming not allowed by serverdebug1: SSH2_MSG_SERVICE_REQUEST sentdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickey,passworddebug1: Next authentication method: publickeydebug1: Offering RSA public key: /home/job/.ssh/id_rsadebug1: Authentications that can continue: publickey,passworddebug1: Trying private key: /home/job/.ssh/id_dsadebug1: Trying private key: /home/job/.ssh/id_ecdsadebug1: Next authentication method: passwordjob@192.168.0.2's password: debug1: Authentication succeeded (password).Authenticated to 192.168.0.2 ([192.168.0.2]:22).debug1: channel 0: new [client-session]debug1: Requesting no-more-sessions@openssh.comdebug1: Entering interactive session.debug1: Sending environment.debug1: Sending env LANG = en_US.UTF-8debug1: Sending command: scp -v -t -- ~ ________________________________________debug1: client_input_channel_req: channel 0 rtype exit-status reply 0debug1: channel 0: free: client-session, nchannels 1debug1: fd 0 clearing O_NONBLOCKdebug1: fd 1 clearing O_NONBLOCKTransferred: sent 2120, received 1872 bytes, in 0.3 secondsBytes per second: sent 7783.1, received 6872.6debug1: Exit status 0and$ type scpscp is hashed (/usr/bin/scp)
SCP fails without error
scp
Ok LOL, I just figured out what the problem is.Since I like cows so much, I've put fortune | cowsay at the top of my .bashrc file which produces output like the following when starting bash: _______________________________________< You will lose an important disk file. > ---------------------------------------        \   ^__^         \  (oo)\_______            (__)\       )\/\                ||----w |                ||     ||This is all fine (and sometimes funny) when running bash interactively. However, bash reads ~/.bashrc when it is interactive and not a login shell, or when it is a login shell and its parent process is rshd or sshd. When you run scp, the server starts a shell which starts a remote scp instance. The output from .bashrc confuses scp because it is sent the same way the scp protocol data is sent. This is apparently a known bug, see here for more details.Also note that the underscores I mentioned in the question are those in the top line of the text balloon.So the solution was simple: I put the following at the top of .bashrc:# If not running interactively, don't do anything[[ $- == *i* ]] || returnThis line is present in the default .bashrc but was put way down because of my many (apparently careless) edits.