-
-
Notifications
You must be signed in to change notification settings - Fork 196
FreeBSD
Jose Luis Duran edited this page Jun 28, 2025
·
4 revisions
Note
Taken from: https://github.com/bsdlabs/ssh-hardening
These instructions have been tested against the following versions:
- 13.5-RELEASE
- 14.3-RELEASE
- 14.0-STABLE
- 15.0-CURRENT
-
Remove existing key-pairs, disable DSA & ECDSA
rm -f /etc/ssh/ssh_host_* sysrc sshd_dsa_enable="no" sysrc sshd_ecdsa_enable="no" sysrc sshd_ed25519_enable="yes" sysrc sshd_rsa_enable="yes"
-
Regenerate RSA and Ed25519 keys
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 Diffie-Hellman moduli smaller than 3071
awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.safe mv /etc/ssh/moduli.safe /etc/ssh/moduli
-
Restrict supported key exchange, cipher, and MAC algorithms
printf "\n# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com\n# hardening guide.\nKexAlgorithms sntrup761x25519-sha512,[email protected],mlkem768x25519-sha256,curve25519-sha256,[email protected],diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512\n\nCiphers [email protected],aes256-ctr,aes192-ctr,[email protected],aes128-ctr\n\nMACs [email protected],[email protected],[email protected]\n\nHostKeyAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nCASignatureAlgorithms [email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nHostbasedAcceptedAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\nPubkeyAcceptedAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n" >> /etc/ssh/sshd_config
-
Restart sshd
service sshd restart
-
Run the following in a terminal to harden the OpenSSH client for the local user
mkdir -p -m 0700 ~/.ssh; printf "\nHost *\n Ciphers [email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr\n\n KexAlgorithms sntrup761x25519-sha512,[email protected],mlkem768x25519-sha256,curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\n\n MACs [email protected],[email protected],[email protected]\n\n HostKeyAlgorithms [email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\n CASignatureAlgorithms [email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256\n\n HostbasedAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256\n\n PubkeyAcceptedAlgorithms [email protected],[email protected],[email protected],ssh-ed25519,[email protected],rsa-sha2-512,[email protected],rsa-sha2-256\n" >> ~/.ssh/config