How does OpenSSH decide which host key to use?
Solution 1:
The order is selected by the client using the HostKeyAlgorithms
config option. The default on my system (according to the manpage) is:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- ecdsa-sha2-nistp256
- ecdsa-sha2-nistp384
- ecdsa-sha2-nistp521
- ssh-ed25519
- ssh-rsa
- ssh-dss
To override this, do something like:
ssh -oHostKeyAlgorithms=ssh-ed25519 [email protected]
Solution 2:
And more importantly, why has OpenSSH decided give the ECDSA algorithm first priority?
ECDSA was introduced into openssh with version 5.7, you may find the Release notes here. In particular, it is stated:
Implement Elliptic Curve Cryptography modes for key exchange (ECDH) and host/user keys (ECDSA) as specified by RFC5656. ECDH and ECDSA offer better performance than plain DH and DSA at the same equivalent symmetric key length, as well as much shorter keys.
.......
Certificate host and user keys using the new ECDSA key types are supported - an ECDSA key may be certified, and an ECDSA key may act as a CA to sign certificates.
ECDH in a 256 bit curve field is the preferred key agreement algorithm when both the client and server support it. ECDSA host keys are preferred when learning a host's keys for the first time, or can be learned using ssh-keyscan(1).
Also, RFC 5656 states:
Many estimates consider that 2^80-2^90 operations are beyond feasible, so that would suggest using elliptic curves of at least 160-180 bits. The REQUIRED curves in this document are 256-, 384-, and 521-bit curves; implementations SHOULD NOT use curves smaller than 160 bits