Why
Per Mozilla’s OpenSSH guidelines for OpenSSH 6.7+, “all Diffie-Hellman moduli in use should be at least 3072-bit-long”. The Diffie-Hellman algorithm is used by SSH to establish a secure connection. The larger the moduli (key size) the stronger the encryption.How It Works
SSH uses Diffie-Hellman key exchange to establish secure connections. The strength of this key exchange depends on the size of the moduli used. Smaller moduli (less than 3072 bits) are considered weak and potentially vulnerable to attacks. The/etc/ssh/moduli file contains precomputed Diffie-Hellman groups that SSH can use during key exchange. By removing the shorter, weaker keys from this file, we ensure SSH only uses strong cryptographic parameters.
Goals
- Remove all Diffie-Hellman keys that are less than 3072 bits long
Steps
Remove short moduli
Remove moduli shorter than 3072 bits:This command:
- Uses
awkto filter lines where the 5th field (the moduli size) is >= 3071 - Writes the filtered content to a temporary file
- Replaces the original file with the filtered version
Verify the changes
Check that only strong moduli remain:This command should return no output, indicating all weak moduli have been removed.
Understanding the Moduli File
The/etc/ssh/moduli file contains Diffie-Hellman groups in this format:
- Time: Timestamp when the moduli was generated
- Type: Type of test performed
- Tests: Number of tests performed
- Tries: Number of attempts
- Size: The size of the moduli in bits (this is what we’re filtering on)
- Generator: The generator value
- Modulus: The actual modulus value
The 5th field (Size) is what determines the strength of the key exchange. By filtering to keep only entries where this value is >= 3071, we ensure SSH only uses strong cryptographic parameters.
Security Impact
Removing short Diffie-Hellman keys:- Prevents the use of weak cryptographic parameters
- Protects against attacks on smaller key sizes
- Ensures compliance with modern security standards
- May slightly reduce compatibility with very old SSH clients (though this is unlikely to be an issue)