The community has indicated that the following instructions work for macOS 13 (Ventura) and 14 (Sonoma).
Note: all commands below are to be executed as the root user.
- Re-generate the RSA and ED25519 keys
rm /etc/ssh/ssh_host_*
ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
- Remove small Diffie-Hellman moduli
awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe
mv /etc/ssh/moduli.safe /etc/ssh/moduli
- Enable the RSA and ED25519 HostKey directives in the /etc/ssh/sshd_config file
/usr/bin/sed -i .orig -E 's/^\#(HostKey \/etc\/ssh\/ssh_host_(rsa_key|ed25519_key))/\1/' sshd_config
- Restrict supported key exchange, cipher, and MAC algorithms
[ -d /etc/ssh/sshd_config.d ] || /bin/mkdir etc/ssh/sshd_config.d
echo '
# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com
# hardening guide.
KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com
HostKeyAlgorithms ssh-ed25519,rsa-sha2-512,rsa-sha2-256' > /etc/ssh/sshd_config.d/99_hardening.conf
- Restart OpenSSH server
sudo launchctl stop com.openssh.sshd
sudo launchctl start com.openssh.sshd
Validated versions