网站SSH密钥登录失败怎么办?
系统级排查流程:
- 客户端调试模式:
bash
ssh -vvv -i ~/.ssh/your_key user@host - 服务器端关键检查:
< >验证SSH服务配置:bash< >检查密钥文件权限:grep -E 'PubkeyAuthentication|AuthorizedKeysFile' /etc/ssh/sshd_configbashls -la ~/.ssh/ chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys - SELinux/AppArmor检查:
bash
# SELinux getsebool -a | grep ssh # AppArmor aa-status | grep ssh
- 密钥格式转换(适用于不同客户端):
bash
ssh-keygen -p -f ~/.ssh/id_rsa # 修改密钥密码 ssh-keygen -e -f ~/.ssh/id_rsa > id_rsa.pem # 格式转换 - 临时启用其他认证方式:
bash
sed -i 's/PasswordAuthentication no/yes/' /etc/ssh/sshd_config systemctl restart sshd - 审计日志分析:
bash
journalctl -u sshd --since "1 hour ago" | grep -i error
- 使用ED25519算法生成更安全的密钥:
bash
ssh-keygen -t ed25519 -C "your_comment" - 配置强制密钥认证:
bash
echo -e "\nAuthenticationMethods publickey" >> /etc/ssh/sshd_config - 设置密钥使用期限(需要OpenSSH 8.2+):
bash
ssh-keygen -O validity-time=30d -f ~/.ssh/id_ed25519

更新时间:2025-06-03 09:50:13
