SCP失败无误


45

一段时间以来,我一直在经历SCP的非常奇怪的行为:每当我尝试复制文件时,SCP的输出都会包含一串下划线,并且文件不会被复制。

$ scp test.txt 192.168.0.2:~
job@192.168.0.2's password: 
 ________________________________________

当我使用Midnight Commander创建SSH连接并复制文件时,它确实起作用。

有关我的机器的一些信息:

$ ssh -V
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010

$ uname -a
Linux squatpc 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:05:41 UTC 2011 i686 i686 i386 GNU/Linux

我正在运行Kubuntu 11.04。

编辑:评论所要求的更多信息:

$ 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 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: 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 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/job/.ssh/id_rsa-cert type -1
debug1: identity file /home/job/.ssh/id_dsa type -1
debug1: identity file /home/job/.ssh/id_dsa-cert type -1
debug1: identity file /home/job/.ssh/id_ecdsa type -1
debug1: identity file /home/job/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1 Debian-1ubuntu3
debug1: match: OpenSSH_5.8p1 Debian-1ubuntu3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-1ubuntu3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 28:f3:2b:31:36:43:9b:07:d8:33:ca:43:4f:ca:6c:4c
debug1: Host '192.168.0.2' is known and matches the ECDSA host key.
debug1: Found key in /home/job/.ssh/known_hosts:20
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/job/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/job/.ssh/id_dsa
debug1: Trying private key: /home/job/.ssh/id_ecdsa
debug1: Next authentication method: password
job@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.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: scp -v -t -- ~
 ________________________________________
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 2120, received 1872 bytes, in 0.3 seconds
Bytes per second: sent 7783.1, received 6872.6
debug1: Exit status 0

$ type scp
scp is hashed (/usr/bin/scp)

1
尝试使用-v在复制过程中获取一些调试信息。
NovemberBitTony 2011年

另外,以防万一...的输出是type scp什么?
rozcietrzewiacz 2011年

@EightBitTony:看我的编辑。
工作

@rozcietrzewiacz:也请参阅我的编辑:-)
Job

2
如果这样做ssh 192.168.0.2 echo hello,您除了得到什么输出之外hello吗?
吉尔(Gilles)'所以

Answers:


77

好的,大声笑,我只是想出了问题所在。

由于我非常喜欢母牛,因此我将其放在文件fortune | cowsay的顶部,.bashrc该文件在启动时会产生如下所示的输出bash

 _______________________________________
< You will lose an important disk file. >
 ---------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

bash交互式运行时,一切都很好(有时很有趣)。但是,~/.bashrc当bash 是交互式而不是登录shell时,或者当它是登录shell并且其父进程为rshdorsshd时,bash会读取。运行时scp,服务器将启动一个外壳程序,该外壳程序将启动一个远程scp实例。来自输出的.bashrc混乱,scp因为它的发送方式与scp发送协议数据的方式相同。这显然是一个已知的错误,有关更多详细信息,请参见此处

还要注意,我在问题中提到的下划线是文本气球顶部的那些下划线。

所以解决方案很简单:我将以下内容.bashrc放在远程(目标)计算机的顶部:

# If not running interactively, don't do anything
[[ $- == *i* ]] || return

该行默认存在,.bashrc但由于我的许多编辑(显然是粗心的)而被放低了。


echo "don't have a cow" | cowsay
斯蒂芬·吉梅内斯

哇,在中断了数月的scp之后,您终于为我阐明了答案。我永远都不会想到这一点。我只是做了一个mv ~/.bashrc ~/.bashrc.bak测试,以确保这是问题所在,而在我这样做之后它就起作用了。
Jondlm

@ScottStensland这需要放在遥控器的顶部.bashrc。与本地无关。请注意,我的评论中有一个错字(答案是正确的):是*i*,不是*-*
吉尔斯(Gillles)“所以-别再邪恶了”

不不不。rtfm。bashrc是针对非交互式shell运行的。如果您希望在登录时获得快乐的牛信息,请更改bash_profile。如果你想牛智慧每次打开然后X-Window的尝试找出如果这是一个MANY场景中,你不应该写终端- unix.stackexchange.com/questions/9605/...
symcbean

5

AFAIK,启用无障碍的正确方法与脚本中scpstdout的条件无关~/.bashrc,而与仅将屏幕输出限制到~/.bash_profile脚本有关。至少这就是我的发行版(CentOS)的工作方式。

为清楚起见进行编辑:

  1. 根据“所有”远程连接的需要,仅在〜/ .bashrc文件中放置行(即,设置某些ENV变量是可以的,但不能回显人类可读的文本。)
  2. 青年汽车

介意?即如何将屏幕输出限制为.bash-profile?
javadba 2014年

1
通过screen输出,我的意思echo "Greetings, Master"或其他任何显示输出到终端窗口。不要将其放在〜/ .bashrc中-请将其保留在〜/ .bash_profile脚本中。
Mark Hudson
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.