LinuxからWindowsにファイルをコピーしようとすると、scpがハングしました。

LinuxからWindowsにファイルをコピーしようとすると、scpがハングしました。

次のscp構文を使用して、Linux red-hat 5からWindowsコンピュータ(Temディレクトリの下)に多数のファイルを転送しました。

SSHサーバーはWindowsシステムにすでにインストールされています。シェルスクリプトで次の行を使用します。

sshpass -p '$password'  /usr/bin/scp -o StrictHostKeyChecking=no  $FILE [email protected]:'D:/Temp'

ほとんどの場合、ファイル転送は成功しますが、時にはscpファイル転送中に停止するようです。 pingなどの接続が正常に表示されます。

scp(長い時間が経過した後)次のエラーが発生します。

ssh_exchange_identification: read: Connection reset by peer
  1. なぜscp不安定で止まるのですか?この問題に対する解決策はありますか?
  2. もう一つの良いオプションがありますかscp? (100%安定性が必要であることを考慮すると)

ベストアンサー1

ハードウェア

私はあまり懐疑的ではありませんscp。場合によっては、次のいずれかにハードウェアの問題があるようです。

  1. ネットワークカード(LinuxまたはWindowsホスト)
  2. 配線
  3. スイッチ/ルーター

まず、これらの項目を削除するためにいくつかのベンチマークを実行します。初心者のための次のU&L Q&Aを確認できます。

ソフトウェア

デバッグscpssh

-vより詳細な出力を得るには、両方のコマンドにスイッチを追加できます。たとえば、

# generate sample data
$ dd if=/dev/zero of=10MB.testfile bs=1k count=10k
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.0422862 s, 248 MB/s

$ ls -l 10MB.testfile 
-rw-rw---- 1 saml saml 10485760 Jul 29 17:09 10MB.testfile

# test copy 10MB file
$ scp -v 10MB.testfile remoteserver:~
Executing: program /usr/bin/ssh host removeserver, user (unspecified), command scp -v -t -- ~
OpenSSH_5.5p1, OpenSSL 1.0.0e-fips 6 Sep 2011
debug1: Reading configuration data /home/saml/.ssh/config
debug1: Applying options for *
debug1: Applying options for removeserver
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
Control socket connect(/home/saml/.ssh/[email protected]:22): Connection refused
debug1: Connecting to 192.168.1.200 [192.168.1.200] port 22.
debug1: Connection established.
debug1: identity file /home/saml/.ssh/id_dsa type 2
debug1: identity file /home/saml/.ssh/id_dsa-cert type -1
debug1: identity file /home/saml/.ssh/qm-dev-servers type 1
debug1: identity file /home/saml/.ssh/qm-dev-servers-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.5
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: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.1.200' is known and matches the RSA host key.
debug1: Found key in /home/saml/.ssh/known_hosts:30
debug1: ssh_rsa_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,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/saml/.ssh/id_dsa
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Offering public key: /home/saml/.ssh/qm-dev-servers
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: setting up multiplex master socket
ControlSocket /home/saml/.ssh/[email protected]:22 already exists, disabling multiplexing
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env XMODIFIERS = @im=none
debug1: Sending env LANG = en_US.utf8
debug1: Sending command: scp -v -t -- ~
Sending file modes: C0660 10485760 10MB.testfile
Sink: C0660 10485760 10MB.testfile
10MB.testfile                                                                           100%   10MB   3.3MB/s   00:03····
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 10499080, received 4936 bytes, in 4.0 seconds
Bytes per second: sent 2610912.6, received 1227.5
debug1: Exit status 0

-vより詳細な出力を得るには、別のスイッチを追加できます。たとえば、

$ scp -vvv ...

Windowsファイアウォール

これについてさらに調査中に、ファイアウォールの問題かもしれないという@Gillesの主張を裏付ける解決策を見つけました。回避策は、sshd次のコマンド(管理者権限)を使用して、サービスが実行されているWindows側でヘルスチェックを無効にすることです。

% netsh advfirewall set global statefulftp disable

引用する

おすすめ記事