web-dev-qa-db-ja.com

JSchException:アルゴリズムのネゴシエーションが失敗する

JSch(0.1.44-1)でsshを介してリモートsftpサーバーに接続しようとしていますが、「session.connect();」の間に私はこの例外を受け取っています:

com.jcraft.jsch.JSchException: Algorithm negotiation fail at 
com.jcraft.jsch.Session.receive_kexinit(Session.Java:529) at 
com.jcraft.jsch.Session.connect(Session.Java:291) at com.jcraft.jsch.Session.connect(Session.Java:154)
... 

JSchからのログ:

INFO: Connecting to xx.xx.xx.xxport 22 
INFO: Connection established 
INFO: Remote version string: SSH-2.0-WeOnlyDo 2.0.6 
INFO: Local version string: SSH-2.0-JSCH-0.1.44 
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: aes256-ctr is not available. 
INFO: aes192-ctr is not available.
INFO: aes256-cbc is not available. 
INFO: aes192-cbc is not available.
INFO: arcfour256 is not available. 
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received 
INFO: Disconnecting from xx.xx.xx.xx port 22 

Linux sftpコマンドでリモートサーバーにログインできます。私はインターネットであらゆる種類の手がかりを見つけようとしていましたが、失敗しました。

Linux sftpコマンドからのデバッグ出力:

OpenSSH_5.5p1-DAM_1.2, OpenSSL 0.9.8r 8 Feb 201

debug1: Reading configuration data /etc/DAM/ssh/ssh_config
debug1: Applying options for *
debug1: Applying options for *.*
debug1: Connecting to xx.xx.xx.xx [xx.xx.xx.xx] port 22.
debug1: Connection established.
debug1: identity file /**/spv_id_rsa.key type -1
debug1: identity file /**/spv_id_rsa.key-cert type -1
debug1: Remote protocol version 2.0, remote software version WeOnlyDo 2.0.6
debug1: no match: WeOnlyDo 2.0.6
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.5p1-DAM_1.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes256-cbc hmac-md5 none
debug1: kex: client->server aes256-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'xx.xx.xx.xx' is known and matches the RSA Host key.
debug1: Found key in ~/.ssh/known_hosts:8
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
debug1: Next authentication method: publickey
debug1: Trying private key: /**/spv_id_rsa.key
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending subsystem: sftp
Connected to xx.xx.xx.xx.
sftp>
37
Marek Dominiak

SSHクライアントとサーバーが共通の実装について試行し同意する場所がいくつかあります。私が知っている2つは暗号化と圧縮です。サーバーとクライアントは使用可能なオプションのリストを作成し、両方のリストで最適なオプションを選択します。

リストに受け入れ可能なオプションがない場合、エラーが発生して失敗します。ここのデバッグ出力から推測していますが、暗号化のための唯一のサーバーオプションは「aes256-cbc hmac-md5 none」です。

JSchはhmac-md5を実行せず、Javaポリシーファイルのため、aes256-cbcは無効になります。

  1. サーバーで利用可能な暗号化ライブラリを増やすには、無制限のポリシーファイルをクライアントにインストールし、aes256-cbcを有効にします(無効になっていることを示すメッセージが消えることを確認してください。 :

    JDK 1.6の場合: http://www.Oracle.com/technetwork/Java/javase/downloads/jce-6-download-429243.html

    JDK 1.7の場合: http://www.Oracle.com/technetwork/Java/javase/downloads/jce-7-download-432124.html

    JDK 1.8の場合: http://www.Oracle.com/technetwork/Java/javase/downloads/jce8-download-2133166.html

  2. または暗号化を無効にしてみてください。

1つ目はサーバーにアクセスできる場合に理想的です(aes128-cbcは十分な暗号化であると信じてください)が、2つ目は理論をすばやくテストするのに十分簡単です。

28
Pace

最後に、サーバーに変更を加えることなく機能するソリューション:

  1. Yvanが示唆するように、最新のjsch.jarをダウンロードします。 http://sourceforge.net/projects/jsch/files/jsch.jar/ jsch-0.1.52.jarは正常に動作します

  2. ダウンロードしたファイルを「...\JetBrains\PhpStorm 8.0.1\lib」に配置し、既存のjschファイルを削除します(PHPStorm 8の場合はjsch-0.1.50.jarです)

  3. PHPStormを再起動すると動作するはずです

Webstormに同じソリューションを使用する

18
brunettdan

受信サーバー(接続先のサーバー)にアルゴリズムを追加するための完全な手順。これはLinuxサーバーであると想定しています。

Sudo /etc/ssh/sshd_config

これをファイルに追加します(最後に追加できます)。

KexAlgorithms [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1

次に、SSHサーバーを再起動します。

Sudo service sshd restart
5
mrmuggles

FWIW、私はJSch 0.1.50の下でこれと同じエラーメッセージがありました。 0.1.52にアップグレードすると、問題は解決しました。

5
cobbzilla

問題は、使用しているJSCH jarのバージョンにあります。

最新のjarに更新します。

私も同じエラーを受け取っていましたが、このソリューションは機能しました。

最新のjarをダウンロードできます

http://www.jcraft.com/jsch/

3
Aditya

JSchの最新バージョンを使用していることを確認してください。 JSch 0.1.31を使用してRedHat 5サーバーに接続しようとすると、まったく同じ問題が発生しました。最新バージョンに更新することで問題は解決しました。

3
TJ von Mechow

私は同じ問題を抱えており、Windows上でNetbeans 8.0とJRE 1.7を実行していました。

https://www.Java.com/fr/download/ からJRE 1.8をインストールしたところです(Version 8が、インストールするとバージョン1.8になります)、修正されました。

2
Yvan

私にとっての解決策は、Oracle無制限のJCEをインストールし、JRE_HOME/lib/securityにインストールすることでした。その後、glassfishを再起動すると、jschを使用してsftpサーバーに接続できました。

1
nettie

サーバー上のsshd_configにKexAlgorithms diffie-hellman-group1-sha1、diffie-hellman-group-exchange-sha‌ 1を追加します。

これは機能しましたが、必ずsshdを再起動してください:Sudo service sshd restart

1
Adamsaurus