I have some machines whose primes in /etc/ssh/moduli
are now considered too weak because they are less than 2048 bits. There are a couple questions on this site concerning the consequences of updating /etc/ssh/moduli
:
- Does changing /etc/ssh/moduli impact previously generated keys?
- https://security.stackexchange.com/a/41947/145516
But neither of these discuss the mechanics of actually updating the file (understandably since those questions focus on what happens after the file is updated, not how to actually update the file). Considering the importance of this, I want to make sure I update the file correctly. Here are a couple of links describing how to run ssh-keygen
to generate primes for a couple Linux flavors:
- Ubuntu: http://manpages.ubuntu.com/manpages/jammy/en/man1/ssh-keygen.1.html#moduli%20generation
- RHEL: https://www.redhat.com/en/blog/primes-parameters-and-moduli (See the section ** Generating primes in advance**.
Using either of those methods, as appropriate for the OS, can I then simply copy the resulting file down on top of /etc/ssh/moduli
?
Thus, to be explicit, I intend to do the following for my RHEL 7 system:
ssh-keygen -G candidates -b 2048
ssh-keygen -T moduli -f candidates
sudo cp candidates /etc/ssh/moduli
My first question: can someone confirm whether this is correct? If, broadly speaking, that is correct, how can I interpret the ssh-keygen
output of those two commands to see whether they are succeeding or not. I'm cautious because the output of that second ssh-keygen -T
test execution outputs this:
$ ssh-keygen -T moduli -f candidates
Wed Apr 27 15:02:51 2022 Found 33 safe primes of 46769 candidates in 224 seconds
I do not know how to interpret this output, and the man page for -T
simply says Test DH group exchange candidate primes (generated using the -G option) for safety
with no further information on how to interpret the output. So that leaves me with the following follow-up questions to the first one:
- When my output says that it found "33 safe primes", does that mean I should filter the file for those 33 "safe" primes and not use the other candidates in the file somehow? Or is the output an indication that the file "passes" its inspection and the file is thus "safe"?
- What output should I expect from this test run if the file is deficient in some way? I assume since it is a "test" run that the file generated from
ssh-keygen -G
can fail somehow. - For these commands, can I ignore the output and simply rely upon 0 exit codes from these commands to communicate to me that there were no problems in generating or testing the file?