Fix ssh ciphers and key exchange problem towards older network hardware

Feb 12, 2023 • olanys Tags: , , ,

Cipher or key exchange error when trying ssh towards older Cisco switches and other older networking hardware.

You get an error like
Unable to negotiate with 10.1.1.2 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1

The support for these cryptos were removed in OpenSSH 7.2 (2016-02-29)

This release disables a number of legacy cryptographic algorithms
by default in ssh:

 * Several ciphers blowfish-cbc, cast128-cbc, all arcfour variants
   and the rijndael-cbc aliases for AES.

 * MD5-based and truncated HMAC algorithms.


Either add ciphers for the specific host:

# cat ~/.ssh/config
Host 10.1.1.2
    KexAlgorithms +diffie-hellman-group1-sha1
    Ciphers +aes256-cbc


Or add ciphers for the wildcard:

# cat ~/.ssh/config
Host *
    KexAlgorithms +diffie-hellman-group1-sha1
    Ciphers +aes256-cbc



You may also see another newer error if you need SHA-1 based HostKeys.
From OpenSSH 8.8 (2021-09-26)

This release disables RSA signatures using the SHA-1 hash algorithm
by default. This change has been made as the SHA-1 hash algorithm is
cryptographically broken, and it is possible to create chosen-prefix
hash collisions for <USD$50K

For most users, this change should be invisible and there is
no need to replace ssh-rsa keys. OpenSSH has supported RFC8332
RSA/SHA-256/512 signatures since release 7.2 and existing ssh-rsa keys
will automatically use the stronger algorithm where possible.

Incompatibility is more likely when connecting to older SSH
implementations that have not been upgraded or have not closely tracked
improvements in the SSH protocol. For these cases, it may be necessary
to selectively re-enable RSA/SHA1 to allow connection and/or user
authentication via the HostkeyAlgorithms and PubkeyAcceptedAlgorithms
options. For example, the following stanza in ~/.ssh/config will enable
RSA/SHA1 for host and user authentication for a single destination host:

    Host old-host
        HostkeyAlgorithms +ssh-rsa
    	PubkeyAcceptedAlgorithms +ssh-rsa