sshd_config.d drop-in ignored: the first value wins (KexAlgorithms and others)
A setting in /etc/ssh/sshd_config.d/99-something.conf seems to be ignored. sshd uses the first value it reads for most keywords, so an earlier file wins.
You add a file such as /etc/ssh/sshd_config.d/99-pqc.conf with a KexAlgorithms line, reload sshd, and nothing changes. The file is read, but another value was read first.
Why: first obtained value wins
The sshd_config manual says that, unless noted otherwise, for each keyword the first obtained value is used. Later lines for the same keyword are ignored.
Include brings other files in at the point where the Include line is. A glob such as /etc/ssh/sshd_config.d/*.conf is expanded and read in lexical order. So:
- A file whose name sorts early (
00-…,10-…) beats one that sorts late (99-…). - If
Includeis near the top ofsshd_config, the drop-in files beat lines further down insshd_configitself. Debian'sopenssh-serverpackage ships itssshd_configwithInclude /etc/ssh/sshd_config.d/*.confbefore any other setting. If a line insshd_configcomes before theInclude, it beats every drop-in file.
ssh_config on the client works the same way: the first obtained value for each option is used.
See what sshd will actually use
sudo sshd -t
sudo sshd -T | grep -i '^kexalgorithms'
grep -rin 'kexalgorithms' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
sshd -t checks the configuration for errors. sshd -T prints the effective settings after all files are read. The grep shows every file that sets the keyword; the first one in reading order is the one in force.
Fix it
- Give your file a name that sorts before the one that wins, for example
00-pqc.conf, or - Remove or change the earlier line.
Then run sudo sshd -t, reload the service, and check again with sshd -T. Keep your current session open until a new login works.
Example: post-quantum key exchange only
To offer only the post-quantum hybrid key exchanges in a current OpenSSH, put this in a file that is read first:
KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512,[email protected]
Check that your sshd knows these names with ssh -Q kex on the server; older versions do not have all of them. Before you do this, check that every client you connect with, including apps on phones and tablets, supports at least one of them. Clients that support none of them will then fail with "no matching key exchange method found": see SSH "no matching key exchange method" and "no matching host key type" errors. For the client-side warning about key exchange, see SSH "connection is not using a post-quantum key exchange algorithm".
Related
- SSH "connection is not using a post-quantum key exchange algorithm"
- SSH "no matching key exchange method" and "no matching host key type" errors
- SSH "Bad configuration option" in ~/.ssh/config or sshd_config
- The ssh config file
- Turn off the SSH login message: motd, "Last login" and the pre-login banner