The KexAlgorithms
configuration option is correct, but you want to use a -
at the beginning of the line like:
KexAlgorithms -diffie-hellman-group1-sha1,diffie-hellman-group1-sha256,diffie-hellman-group14-sha1,diffie-hellman-group14-sha256,diffie-hellman-group15-sha256,diffie-hellman-group15-sha512,diffie-hellman-group16-sha256,diffie-hellman-group16-sha512,diffie-hellman-group17-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha512
Because:
If the specified list begins with a ‘-’ character, then the specified algorithms (including wildcards) will be removed from the default set instead of replacing them.
Note: you can wildcard this e.g. KexAlgorithms -diffie-hellman-group*
NOTE2: This doesn't work for older versions of openssh
, on CentOS 7 for example the -
doesn't work and you have to explicitly state what algorithms you want to use:
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
You also want to control the number of unauthenticated connections with the following settings:
MaxStartups 10:30:100
PerSourceMaxStartups 1
PerSourceNetBlockSize 32:128
You can find a list of available KexAlgorithms using this command:
sudo sshd -T |grep kexalgorithms
Output before blocking Diffie-Hellman:
kexalgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
and after:
kexalgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
or you could us nmap
:
nmap --script ssh2-enum-algos -sV -p 22 localhost
References
dheater git repo
sshd_config KexAlgorithms