For the RedHat 8 / CentOS 8 systems use below steps to disable insecure key exchange algorithm diffie-hellman-group-exchange-sha1
Step 1: To list out openssh client supported Key Exchange Algorithms algorithms
# ssh -Q kex
Step 2: To list out openssh server supported Key Exchange Algorithms algorithms
# sshd -T | grep kex
Step 3: Remove diffie-hellman-group-exchange-sha1 SSH Weak Key Exchange Algorithms.
# vi /etc/ssh/sshd_config
Step 4: Take the backup of the below listed openssh server & client configuration files.
# cp -p /etc/crypto-policies/back-ends/openssh.config /etc/crypto-policies/back-ends/openssh.config-bkp
# cp -p /etc/crypto-policies/back-ends/opensshserver.config /etc/crypto-policies/back-ends/opensshserver.config-bkp
Step 5: Now remove diffie-hellman-group-exchange-sha1 Weak Key Exchange Algorithms from both openssh server & client configuration files.
# vi /etc/crypto-policies/back-ends/openssh.config
# vi /etc/crypto-policies/back-ends/opensshserver.config
Step 5: Verify diffie-hellman-group-exchange-sha1 Exchange Algorithms entry removed properly or not.
# grep -i diffie-hellman-group-exchange-sha1 /etc/crypto-policies/back-ends/openssh.config
# grep -i diffie-hellman-group-exchange-sha1 /etc/crypto-policies/back-ends/opensshserver.config
There should not be any output for above listed commands.
Step 6: Restart the sshd.service
# systemctl restart sshd.service
# systemctl status sshd.service
Step 7: Now you can establish the SSH connection with verbose mode and there should not be any debug kex names logs for diffie-hellman-group-exchange-sha1
# ssh -vvv username@IP-Address
# ssh -o KexAlgorithms=diffie-hellman-group-exchange-sha1 user-name@127.0.0.1
# nmap --script ssh2-enum-algos -sV -p 22 127.0.0.1
For the RedHat 7 systems use below command to disable Insecure key exchange algorithms in use
- diffie-hellman-group-exchange-sha1
- diffie-hellman-group1-sha1
Execute below commands one after another.
# cp -p /etc/ssh/ssh_config /etc/ssh/ssh_config-bkp
# for kex in `ssh -Q kex| grep -vE "diffie-hellman-group-exchange-sha1|diffie-hellman-group1-sha1"|paste -s -d,`; do echo "KexAlgorithms $kex"; done >> /etc/ssh/ssh_config
# sudo systemctl restart sshd; systemctl status sshd
# ssh -vvv username@IP-Address
# ssh -o KexAlgorithms=diffie-hellman-group-exchange-sha1 user-name@127.0.0.1