ssh认证提示receive packet: type 51

错误日志

ssh -vvv -i ./u01 tunnel_user@10.10.10.10

你的 -vvv 日志来看,关键点是这一行:

debug1: Trying private key: u01
debug3: sign_and_send_pubkey: using publickey with RSA SHA256:...
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password

意思是:

  1. 客户端尝试用私钥 u01 认证。
  2. 服务器拒绝了这个公钥认证(返回 51)。
  3. SSH 最后才回退到密码认证。

分析原因

结合你的情况和日志,最常见的原因是:

  1. 私钥格式或类型不被服务器支持

    • 服务器是 OpenSSH 7.4(比较老),如果你的密钥是 OpenSSH 新格式(BEGIN OPENSSH PRIVATE KEY),可能不兼容 RSA SHA2 或其他算法。
    • 日志里看到 signing using rsa-sha2-512,而旧版 OpenSSH 7.4 默认可能只支持 ssh-rsa
  2. 服务器 authorized_keys 不匹配或权限问题

    • 确认 ~u01/.ssh/authorized_keys 中的公钥和你本地 u01 私钥对应。

    • 权限必须:

      1
      2
      chmod 700 ~/.ssh
      chmod 600 ~/.ssh/authorized_keys
  3. 客户端指定的密钥路径错误或权限不足

    • 你命令里 -i u01,确保 u01 文件在当前目录,且权限是 600
  4. SSH 配置限制

    • 服务器 /etc/ssh/sshd_config 里:

      1
      2
      PubkeyAuthentication yes
      PasswordAuthentication yes # 允许回退密码
    • 如果 AuthorizedKeysFile 修改过,确保路径正确。

  5. SSH 配置一定要多检查是否正确

1
sshd -t

💡 总结
大多数情况都是:

    1. authorized_keys 权限不对
    1. SSH 客户端私钥路径或权限不对
    1. SSHD 配置未开启公钥认证