三浦ノート

自分の経験したことを検索可能にしていくブログ.誰かの役に立ってくれれば嬉しいです.

Jschで「com.jcraft.jsch.JSchException: Algorithm negotiation fail」とエラーが出た原因

javaのsftpクライアントのJsch 0.1.51を使うシステムに、OpenSSH_8.4p1をつかってsftp接続すると

com.jcraft.jsch.JSchException: Algorithm negotiation fail

というエラーがでました。

原因は、Jschのバージョンが古くてOpenSSH_8.4p1で使っている鍵交換アルゴリズムに対応していないためでした。

OpenSSH_8.4p1が対応している鍵交換アルゴリズムは以下です。

# ssh -Q kex
diffie-hellman-group1-sha1
diffie-hellman-group14-sha1
diffie-hellman-group14-sha256
diffie-hellman-group16-sha512
diffie-hellman-group18-sha512
diffie-hellman-group-exchange-sha1
diffie-hellman-group-exchange-sha256
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
curve25519-sha256
curve25519-sha256@libssh.org
sntrup4591761x25519-sha512@tinyssh.org

Jschのバージョンを0.1.55に上げると解決しました。

別の手段として、逆にOpenSSHのバージョンを下げるという手もあると思います。