on fedora 40
tl;dr
here's a one liner:
echo "PubkeyAcceptedAlgorithms $(grep \
PubkeyAcceptedAlgorithms \
/etc/crypto-policies/back-ends/opensshserver.config \
| cut -d ' ' -f 2 \
| tr ',' '\n' \
| grep --invert-match -E 'ecdsa|rsa' \
| head -c -1 \
| tr '\n' ',')" | sudo tee /etc/ssh/sshd_config.d/39-ed25519-only.conf
q.e.d.
there's nothing of interest in /etc/ssh/sshd_config, so we explore deeper:
sudo ls -ahl /etc/ssh/sshd_config.d
which yields:
-rw-------. 1 root root 412 Jan 25 2024 40-redhat-crypto-policies.conf
-rw-------. 1 root root 307 Jan 25 2024 50-redhat.conf
there's nothing of interest in /etc/ssh/sshd_config.d/50-redhat.conf, but:
sudo cat /etc/ssh/sshd_config.d/40-redhat-crypto-policies.conf
yields:
# This system is following system-wide crypto policy. The changes to
# crypto properties (Ciphers, MACs, ...) will not have any effect in
# this or following included files. To override some configuration option,
# write it before this block or include it before this file.
# Please, see manual pages for update-crypto-policies(8) and sshd_config(5).
Include /etc/crypto-policies/back-ends/opensshserver.config
this is interesting for two reasons:
- we learn that we need our override config to be read before the default distro config
- we learn the real location of the default distro config
so, we analyse that:
grep PubkeyAcceptedAlgorithms /etc/crypto-policies/back-ends/opensshserver.config \
| cut -d ' ' -f 2 \
| tr ',' '\n'
yields the distro default list of accepted algorithms:
ecdsa-sha2-nistp256
ecdsa-sha2-nistp256-cert-v01@openssh.com
sk-ecdsa-sha2-nistp256@openssh.com
sk-ecdsa-sha2-nistp256-cert-v01@openssh.com
ecdsa-sha2-nistp384
ecdsa-sha2-nistp384-cert-v01@openssh.com
ecdsa-sha2-nistp521
ecdsa-sha2-nistp521-cert-v01@openssh.com
ssh-ed25519
ssh-ed25519-cert-v01@openssh.com
sk-ssh-ed25519@openssh.com
sk-ssh-ed25519-cert-v01@openssh.com
rsa-sha2-256
rsa-sha2-256-cert-v01@openssh.com
rsa-sha2-512
rsa-sha2-512-cert-v01@openssh.com
to get the same list with rsa and ecdsa algorithms removed:
grep PubkeyAcceptedAlgorithms /etc/crypto-policies/back-ends/opensshserver.config \
| cut -d ' ' -f 2 \
| tr ',' '\n' \
| grep --invert-match -E 'ecdsa|rsa' \
| head -c -1 \
| tr '\n' ','
normally a higher numbered conf.d file denotes precedence when it's config is read last and overwrites an earlier declaration, but we learned earlier:
To override some configuration option, write it before this block or include it before this file
so we create a lower numbered file at:
/etc/ssh/sshd_config.d/39-ed25519-only.conf
containing a single line:
PubkeyAcceptedAlgorithms ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com
then a restart of the sshd server should make our new accepted key algorithm settings take effect:
sudo systemctl restart sshd.service
we can verify it has worked by attempting an ssh connection with an rsa key:
ssh -v -i ~/.ssh/id_rsa hostname.example.com
which yields:
...
Skipping ssh-rsa key /home/user/.ssh/id_rsa - corresponding algorithm not supported by server
...