SSH 配置安全加固
linux sshd_config ssh环境: Debian 13
配置文件 /etc/ssh/sshd_config
额外配置
Include /etc/ssh/sshd_config.d/*.conf
会加载该目录下的所有 .conf 文件,优先级可能覆盖主配置(后加载的生效)
修改配置项
#允许 root 登录,但禁止使用密码,只能用 SSH 密钥登录
PermitRootLogin prohibit-password
#每个连接最多尝试 3 次认证
MaxAuthTries 3
#启用 SSH key 登录
PubkeyAuthentication yes
#禁用密码登录
PasswordAuthentication no
#禁止空密码
PermitEmptyPasswords no
加载配置
在让配置生效前,务必先开一个 SSH 窗口测试登录,确认能正常登录后,再关闭旧连接。
不会断开当前 SSH 连接
systemctl reload ssh
或
直接重启ssh服务(可能断连)
systemctl restart ssh
在执行 reload/restart 前先检查:
sshd -t
如果配置正确,不会有任何输出。