오류 없이 SCP가 실패함

오류 없이 SCP가 실패함

나는 한동안 SCP에서 매우 이상한 동작을 경험했습니다. 파일을 복사하려고 할 때마다 SCP의 출력에 밑줄이 많이 포함되어 파일이 복사되지 않습니다.

$ scp test.txt 192.168.0.2:~
[email protected]'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

저는 쿠분투 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
[email protected]'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 [email protected]
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

글쎄요 ㅎㅎ 문제가 무엇인지 이제야 알아냈습니다.

나는 소를 너무 좋아하기 때문에 그것을 파일 fortune | cowsay의 맨 위에 두었습니다 .bashrc. 시작하면 다음과 같은 출력이 생성됩니다 bash.

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

bash대화형으로 실행하면 괜찮습니다(때로는 재미있기도 합니다). 그러나 ~/.bashrcbash가 로그인 셸이 아닌 대화형인 경우에는 다음과 같이 읽습니다.또는 로그인 쉘이고 상위 프로세스가 rshd또는sshd. 를 실행하면 scp서버는 원격 scp인스턴스를 시작하는 셸을 시작합니다. 의 출력은 프로토콜 데이터가 전송되는 것과 동일한 방식으로 전송되기 때문에 .bashrc혼란스럽습니다 . 이것은 분명히 알려진 버그입니다.scpscp여기자세한 내용은.

또한 질문에서 언급한 밑줄은 텍스트 풍선의 맨 윗줄에 있는 밑줄입니다.

.bashrc따라서 해결책은 간단합니다. 원격(대상) 시스템의 상단에 다음을 배치합니다.

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

이 줄은 기본값에 존재 .bashrc하지만 제가 여러 번(분명히 부주의하게) 편집했기 때문에 보류되었습니다.

답변2

AFAIK, 차단 해제를 활성화하는 올바른 방법 scp은 스크립트의 stdout 조건보다는 ~/.bashrc단순히 화면 출력을 스크립트로 제한하는 것입니다 ~/.bash_profile. 적어도 내 배포판(CentOS)에서는 그렇습니다.

명확성을 위해 편집됨:

  1. "모든" 원격 연결에 필요한 줄만 ~/.bashrc 파일에 넣습니다. (즉, 특정 ENV 변수를 설정하는 것은 괜찮지만 사람이 읽을 수 있는 텍스트를 에코하는 것은 그렇지 않습니다.)
  2. 청소년MMV

답변3

.bashrc이 문제는 파일이 일부 출력을 생성 하거나 때때로 MOTD(Message Of The Day). 이 -o옵션을 다음과 결합할 수 있습니다 scp.

SSH에 옵션을 전달할 수 있습니다 -o. 이 경우 이와 같은 옵션을 제공하면 RequestTTY=no터미널 출력을 요청하지 않습니다.

scp -o 요청TTY=아니요원천 표적

답변4

scp에 이 버그가 있는지는 잘 모르겠습니다. 제가 이 버그를 사용한 것은 오래 전이었습니다. scp를 rsync로 대체했는데 훨씬 더 잘 작동합니다. Rsync는 거의 모든 Linux 장치에 있어야 합니다.

나는 rsync에 대해 여기에 썼고 여기에 scp에 대해 썼습니다. scp를 통해 많은 수의 작은 파일을 복사하는 가장 좋은 방법은 무엇입니까?

JohnU의 게시물에서는 Rsync에 대해 설명합니다.

관련 정보