mirror of
https://github.com/jtesta/ssh-audit.git
synced 2024-12-22 09:05:10 +01:00
Page:
FreeBSD
Pages
ArubaOS Switch (AOS S) 16.11
Dropbear 2022.83
Fortinet FortiOS
FreeBSD OpenSSH Hardening Guide ‐ FreeBSD Blog
FreeBSD
Home
Mikrotik RouterOS
OPNsense 20.7 and newer
Proxmox VE 7.3 6
SSH Hardening Guides Index
Synology DSM
Ubuntu 22.04 LTS Client Linux Mint 21 Client
Void Linux
Windows 11
macOS 13 (Ventura) & 14 (Sonoma)
3
FreeBSD
Jose Luis Duran edited this page 2024-09-24 10:06:49 -03:00
Note
Taken from: https://github.com/bsdlabs/ssh-hardening
These instructions have been tested against the following versions:
- 12.4-RELEASE
- 12.4-STABLE
- 13.2-RELEASE
- 13.2-STABLE
- 14.0-RELEASE
- 14.0-STABLE
- 15.0-CURRENT
Server
-
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@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\nCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\nMACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com\nHostKeyAlgorithms ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com\n" >> /etc/ssh/sshd_config
-
Restart sshd
service sshd restart
Client
-
Run the following in a terminal to harden the OpenSSH client for the local user
mkdir -p -m 0700 ~/.ssh; printf "\nHost *\n Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\n KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256\n MACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com\n HostKeyAlgorithms 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\n" >> ~/.ssh/config
footer2