直接在/etc/ssh/sshd_config中显式声明强算法列表即可强制禁用不安全算法——openssh仅认配置项,不保留默认;需先用ssh -q命令查本机支持的cipher、mac、kex算法并过滤弱项,再顶格写入ciphers、macs、kexalgorithms三行强算法,同步关闭protocol 1、rsa主机密钥、密码登录和root直连,最后通过sshd -t检测并systemctl reload sshd安全重载。

直接在 /etc/ssh/sshd_config 中显式声明强算法列表,就能强制禁用所有不安全的加密算法和协议版本——OpenSSH 不会保留默认项,只认你写进去的那些。
确认服务器实际支持的算法
别照搬网上的配置,先查清本机 OpenSSH 编译时启用的算法:
- 运行
ssh -Q cipher,跳过含cbc、arcfour、3des、blowfish、cast128的条目 - 运行
ssh -Q mac,避开所有带md5或sha1且无etm@openssh.com后缀的项(如hmac-sha1不安全,hmac-sha2-256-etm@openssh.com安全) - 运行
ssh -Q kex,过滤掉group1-sha1、group14-sha1、diffie-hellman-group1-sha1等弱交换方式
在 sshd_config 中顶格覆盖三类核心参数
用 root 权限编辑配置文件,在末尾删除所有旧的 Ciphers / MACs / KexAlgorithms 行,只保留以下三行(每行必须顶格、无空格、逗号后不加空格、整行不能换行):
PyCharm 2026.2.0.1 Linux版提供 JetBrains 官方 2026.2.0.1 版本安装包,适合需要指定 PyCharm 版本进行 Python 项目开发、运行和调试的用户。
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctrMACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.comKexAlgorithms curve25519-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
同步关闭高风险配套选项
仅改算法不够,还需切断其他攻击入口:
- 确保只用 SSHv2:
Protocol 2(删掉或注释所有含Protocol 1的行) - 停用 RSA 主机密钥:注释或删除所有
HostKey /etc/ssh/ssh_host_rsa_key行,只保留ed25519和ecdsa密钥 - 关闭密码登录(若已配好密钥):
PasswordAuthentication no - 禁止 root 直连:
PermitRootLogin no
验证并安全重载配置
保存后不要直接重启,按顺序操作:
- 语法检测:
sudo sshd -t—— 没输出即通过;有报错必须修正 - 重载服务:
sudo systemctl reload sshd(不中断现有连接,比 restart 更稳妥) - 新开终端测试:
ssh -vv user@localhost,查看日志中kex:、cipher:、mac:行,确认协商的是你设定的算法










