Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

JSch cannot agree on a key exchange, host key or cipher with the SSH server

Your error

com.jcraft.jsch.JSchAlgoNegoFailException: Algorithm negotiation fail: algorithmName="kex" jschProposal="..." serverProposal="..."1 more line it can show

Fix it fast

Most common cause, 1 of 3

The application pins kex to finite-field Diffie-Hellman, which OpenSSH 10 no longer offers

Delete the override so the fork's own list applies; it already begins with mlkem768x25519-sha256, curve25519-sha256 and the ecdh-sha2-nistp curves.

Fix
// delete lines like this one:
// session.setConfig("kex", "diffie-hellman-group14-sha1,diffie-hellman-group1-sha1");
// and drop -Djsch.kex=... from the start script, so JSch's default kex list is used
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

JSchAlgoNegoFailException: Algorithm negotiation fail means the JSch client and the SSH server share no algorithm in one category, named by algorithmName (kex, server_host_key, cipher or mac). With the com.github.mwiede fork 2.28 it is usually a kex list pinned to old Diffie-Hellman against OpenSSH 10, an old server offering only SHA-1 or CBC, or a Java runtime missing curve25519.

  • Applies to JSch fork com.github.mwiede:jsch 2.28.8, OpenSSH 10.x sshd, Java 11 and newer; Java 8 with bcprov-jdk18on 1.87
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Pull the full message from your log and split it into its fields. algorithmName says which category failed, and the two proposals show what each side offered. A message with no fields at all comes from com.jcraft:jsch or a fork release older than 0.2.4, which leads to cause 3.

Run this first
grep -m1 -o 'Algorithm negotiation fail.*' app.log | tr ' ' '\n'

Then find the line you see in this list and open its fix:

  1. 1The application pins kex to finite-field Diffie-Hellman, which OpenSSH 10 no longer offersalgorithmName="kex", jschProposal holds only diffie-hellman-group names, and serverProposal starts with mlkem768x25519-sha256 or curve25519-sha256
  2. 2An old server offers only SHA-1 key exchange or CBC ciphers that the fork leaves outalgorithmName is kex or cipher.s2c, and serverProposal lists only diffie-hellman-group14-sha1, diffie-hellman-group1-sha1, aes128-cbc or 3des-cbc
  3. 3The runtime cannot offer the curve25519 or post-quantum methods a hardened server insists onserverProposal lists only mlkem768x25519-sha256, sntrup761x25519-sha512 and curve25519-sha256, while jschProposal lacks all three; or the message has no fields because the app still uses com.jcraft:jsch 0.1.55

What does the error look like?

  • com.jcraft.jsch.JSchAlgoNegoFailException: Algorithm negotiation fail: algorithmName="kex" jschProposal="..." serverProposal="..."
  • com.jcraft.jsch.JSchException: Algorithm negotiation fail

Cause 1 of 3

The application pins kex to finite-field Diffie-Hellman, which OpenSSH 10 no longer offers

You seealgorithmName="kex", jschProposal holds only diffie-hellman-group names, and serverProposal starts with mlkem768x25519-sha256 or curve25519-sha256

Check

OpenSSH 10.0 removed every diffie-hellman-group and diffie-hellman-group-exchange method from the server's default KexAlgorithms, leaving post-quantum hybrids, curve25519 and the NIST ECDH curves. A kex override written years ago for an older host now leaves nothing in common, so the negotiation fails on kex. Search the code and start scripts for the override.

Check
grep -rnE 'setConfig\("kex"|jsch\.kex' --include='*.java' --include='*.properties' --include='*.sh' .

Fix

Delete the override so the fork's own list applies; it already begins with mlkem768x25519-sha256, curve25519-sha256 and the ecdh-sha2-nistp curves. A host that truly needs an old method gets it appended for its own session only, as in cause 2.

Fix
// delete lines like this one:
// session.setConfig("kex", "diffie-hellman-group14-sha1,diffie-hellman-group1-sha1");
// and drop -Djsch.kex=... from the start script, so JSch's default kex list is used

Verify

The search comes back empty and session.connect() returns without JSchAlgoNegoFailException.

Verify
grep -rnE 'setConfig\("kex"|jsch\.kex' --include='*.java' --include='*.properties' --include='*.sh' . || echo 'no kex override left'

Confirmed by openssh.com

Did this fix it?

Cause 2 of 3

An old server offers only SHA-1 key exchange or CBC ciphers that the fork leaves out

You seealgorithmName is kex or cipher.s2c, and serverProposal lists only diffie-hellman-group14-sha1, diffie-hellman-group1-sha1, aes128-cbc or 3des-cbc

Check

The maintained fork changed its default algorithm order and dropped older methods for safety; its README says older or deprecated algorithms need a configuration change. The code still ships diffie-hellman-group14-sha1, aes128-cbc and 3des-cbc, they are just absent from the default kex and cipher lists, which is why an embedded SFTP box or ageing appliance meets an empty match.

Check
grep -o 'serverProposal="[^"]*"' app.log | head -n 1

Fix

Append the one method the server proposes to the matching list for that session only, keeping the secure defaults in front so newer servers still pick them. Plan an upgrade of the server, since these methods are weak.

Fix
Session session = jsch.getSession(user, host, 22);
session.setConfig("kex", session.getConfig("kex") + ",diffie-hellman-group14-sha1");
session.setConfig("cipher.s2c", session.getConfig("cipher.s2c") + ",aes128-cbc");
session.setConfig("cipher.c2s", session.getConfig("cipher.c2s") + ",aes128-cbc");
session.connect();

Verify

The legacy host connects, while other hosts in the same application keep negotiating modern methods.

Verify
grep -c 'Algorithm negotiation fail' app.log

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The runtime cannot offer the curve25519 or post-quantum methods a hardened server insists on

You seeserverProposal lists only mlkem768x25519-sha256, sntrup761x25519-sha512 and curve25519-sha256, while jschProposal lacks all three; or the message has no fields because the app still uses com.jcraft:jsch 0.1.55

Check

The fork offers curve25519 only when the runtime can run it: its README states that curve25519-sha256 needs Java 11 or Bouncy Castle (bcprov-jdk18on). On Java 8 without that jar only the NIST curves are left, and a server limited to curve25519 or PQ hybrids rejects them. The original com.jcraft 0.1.55 library has no curve25519 at all.

Check
java -version
mvn dependency:tree | grep -iE "jsch|bcprov"

Fix

Run the application on Java 11 or newer, or add bcprov-jdk18on to the classpath. If the tree still shows com.jcraft:jsch, swap in com.github.mwiede:jsch; the README describes it as a drop-in replacement where only the Maven coordinates change.

Fix
<dependency>
  <groupId>com.github.mwiede</groupId>
  <artifactId>jsch</artifactId>
  <version>2.28.8</version>
</dependency>
<dependency>
  <groupId>org.bouncycastle</groupId>
  <artifactId>bcprov-jdk18on</artifactId>
  <version>1.87</version>
</dependency>

Verify

jschProposal in a fresh failure (or the debug log of a successful connect) now includes curve25519-sha256.

Verify
grep -o 'jschProposal="[^"]*"' app.log | tail -n 1 | grep -o curve25519-sha256

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Never replace a JSch algorithm list wholesale; append legacy entries per session so later library defaults still apply.
  • Log getAlgorithmName(), getJSchProposal() and getServerProposal() when catching JSchAlgoNegoFailException, so the next failure explains itself.
  • Read the OpenSSH release notes before upgrading SFTP servers that Java jobs connect to, and run one test transfer from the job's own JVM.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.