以下配置可以提供更高的安全级别,同时保持一定程度的兼容性并降低配置复杂性。
警告:以下配置不兼容所有客户端
# Change the port number avoid automated attack
Port 2222
# Limit to SSH2 only (the default value)
Protocol 2
# Use RSA and Ed25519 host key only
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
# No root login, obvious
PermitRootLogin no
# Log the finger print of public key used to login, provide audit trails. Might take up more storage.
LogLevel VERBOSE
# 2 Factor Authentication. User must present a valid public key first, then enter the correct password to login
AuthenticationMethods publickey,password
# How fast you can type your password?
LoginGraceTime 20
# Key Exchange
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
# Ciphers
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr
# MACs
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,
# Only allow specific group member login via SSH
AllowGroups ssh-user
# Renew encryption key every 30 minutes or 1 GB of transferred data (overkill & generate overhead, use with caution, especially on slow network)
#RekeyLimit 1G 1800
删除 3072 位以下的模数以确保安全(感谢 Mozilla)
awk '$5 >= 3071' /etc/ssh/moduli > /etc/ssh/moduli.tmp && mv /etc/ssh/moduli.tmp /etc/ssh/moduli
通过更多调整可以进一步提高安全性,例如防火墙 (iptables)、fail2ban、Tor 隐藏服务、切换到自定义模数和 tcpwrapper,但这些主题超出了此答案的范围。请注意,配置尚未完成,您可能需要其他重要部分才能使守护程序正常工作。请记住备份原始配置文件,以便在出现任何问题时可以回滚。