How do I change the preferred key exchange mechanism?

Lee Painter

To secure communications, the SSH protocol securely exchanges a set of keys for use in encryption and message authentication.

There are a number of different key exchange mechanisms available, if you have problems connecting to a device and the logs indicate failure during key exchange you many want to try a different default.

To change the default use the following code:

Ssh2Context ssh2Context = (Ssh2Context) con.getContext(SshConnector.SSH2); ssh2Context.setPreferredKeyExchange(Ssh2Context.KEX_DIFFIE_HELLMAN_GROUP14_SHA1);

 

The current default for our 1.6.x API is KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA256 this is one of the most secure key exchange methods available and uses a minimum key size of 2048 bits.

If you have problems connecting to older devices, it may be advisable to try an older mechanism such as KEX_DIFFIE_HELLMAN_GROUP1_SHA1