오류없이 SCP 실패 port 22. debug1: Connection established. debug1: identity file

나는 한동안 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

그리고 저는 쿠분투 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)


답변

좋아 LOL, 방금 문제가 무엇인지 알아 냈습니다.

나는 소를 너무 좋아하기 때문에 시작할 때 다음과 같은 출력을 생성하는 파일 fortune | cowsay의 맨 위에 놓았 습니다 ..bashrcbash

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

bash대화식으로 실행할 때 이것은 모두 훌륭하고 때로는 재미 있습니다. 그러나 bash ~/.bashrc는 대화식이고 로그인 쉘이 아닌 경우 또는 로그인 쉘이고 상위 프로세스가 rshd또는 인sshd 경우 bash를 읽습니다 . 를 실행 scp하면 서버는 원격 scp인스턴스 를 시작하는 셸을 시작 합니다. 프로토콜 데이터가 전송 되는 것과 같은 방식으로 전송되므로 출력이 .bashrc혼동 됩니다. 이것은 분명히 알려진 버그 입니다. 자세한 내용 은 여기 를 참조하십시오.scpscp

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

그래서 해결책은 간단했습니다. 다음을 .bashrc원격 (대상) 컴퓨터 의 맨 위에 놓았습니다 .

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

이 줄은 기본값으로 표시 .bashrc되지만 많은 (아마도 부주의 한) 편집으로 인해 중단되었습니다.


답변

AFAIK, 방해받지 않는 올바른 방법 scp~/.bashrc스크립트 에서 stdout에 대한 조건이 적고 화면 출력을 ~/.bash_profile스크립트로 제한하는 것 입니다. 적어도 그것이 내 배포판 (CentOS)에서 작동하는 방식입니다.

명확성을 위해 편집 :

  1. “모든”원격 연결에 필요한대로 ~ / .bashrc 파일에 행만 넣으십시오 (예 : 특정 ENV 변수 설정은 괜찮지 만 사람이 읽을 수있는 텍스트를 에코하는 것은 아닙니다).
  2. YMMV