Agent admitted failure to sign using the key

本文介绍了一种常见的SSH免密登录问题及其解决方案。当使用ssh-keygen生成密钥并放置到正确位置后,仍可能出现“Agent admitted failure to sign using the key”的错误。文章提供了通过执行ssh-add命令来解决问题的方法。

ssh-keygen 产生出 id_rsa, id_rsa.pub, 已经都放到正确位置(.ssh), 但是联机时却出现下述讯息:

Agent admitted failure to sign using the key

 

解法

于自己的机器上, 执行 ssh-add 或以指定路径的方式执行 ssh-add ~/.ssh/id_rsa, 会出现下述讯息.

Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)

再次联机就正常啰~

测试 SSH 基础连接 # 使用相同参数测试连接 ssh -v -p [端口] -i ~/.ssh/id_rsa [用户名]@[服务器IP] 观察 debug1: Authentications that can continue 后的错误提示: debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: checking without port identifier debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /Users/jolinjiang/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: hostkeys_find_by_key_hostfile: hostkeys file /Users/jolinjiang/.ssh/known_hosts does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /Users/jolinjiang/.ssh/known_hosts2 does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts2 does not exist The authenticity of host '[fox-telemarket.starklotus.com]:36000 ([149.129.235.174]:36000)' can't be established. ED25519 key fingerprint is SHA256:/g3xmRHaPBpl4W5WUIcgHNyzPKjt5gCadvKC/8hlTZY. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '[fox-telemarket.starklotus.com]:36000' (ED25519) to the list of known hosts. debug1: rekey out after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 4294967296 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_ext_info_client_parse: server-sig-algs=<rsa-sha2-256,rsa-sha2-512> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Next authentication method: publickey debug1: get_agent_identities: bound agent to hostkey debug1: get_agent_identities: agent returned 1 keys debug1: Will attempt key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit agent debug1: Will attempt key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit debug1: Offering public key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit agent debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: Offering public key: /Users/jolinjiang/.ssh/id_rsa RSA SHA256:HnRtogpLB7+VvzDy1C4Z/8RX5duqmYaBju7QMAC70hA explicit debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic debug1: No more authentication methods to try. jolinjiang@fox-telemarket.starklotus.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
最新发布
08-27
<think>嗯,用户需要测试SSH连接并解决公钥认证失败的问题。从问题描述看,用户已经遇到了具体的技术障碍,需要详细的排查指导。 用户可能是个系统管理员或开发人员,正在尝试配置基于密钥的SSH登录。这类问题通常涉及多个环节:密钥对生成、公钥部署、权限设置、服务配置等。ta现在明显处于故障排查状态,情绪可能有些焦虑,需要清晰、步骤化的解决方案。 我注意到用户特别要求"debug output",说明ta已经看到错误信息但无法解读。这提示我需要解释常见错误消息的含义,而不仅仅是给出通用步骤。比如"Permission denied (publickey)"这种消息就有多种可能原因。 先从最基础的测试命令开始比较合理:ssh -vT 能提供最详细的连接过程日志。需要强调用户要观察认证阶段的具体错误提示,因为不同提示对应不同解决方案。 权限问题往往是公钥认证失败的首要原因,必须详细说明.ssh目录和文件的正确权限设置。特别是Windows用户容易忽略权限问题,而Linux用户可能遇到selinux干扰。还要提醒用户检查home目录权限,这点经常被遗漏。 公钥部署环节也容易出错:是否追加到了authorized_keys文件末尾?文件格式是否正确?最好给出查看公钥指纹的命令,方便用户比对两端密钥是否匹配。 服务端配置的影响也不能忽略:特别是PasswordAuthentication和PubkeyAuthentication这两个关键选项。用户可能不知道需要重启sshd服务,这点要明确提醒。 最后给出完整的排查流程图会很实用,让用户能系统性地逐步排除可能原因。考虑到用户当前的技术状态,流程图要避免过于复杂,重点突出常见错误点。 需要特别警告私钥文件权限问题——这是高危漏洞。如果用户为图方便设置777权限,必须立即纠正。顺便普及ssh-agent的使用技巧,既安全又便捷。 补充问题设计要覆盖用户可能的后续需求:比如多密钥管理、防火墙影响、审计日志查看等。这些都是排查完成后用户可能想深入学习的知识点。</think>以下是SSH公钥认证失败的排查步骤及调试输出分析,请逐项检查: --- ### **1. 启用详细调试输出** 在客户端执行(`-v` 可叠加至 `-vvv` 最高级): ```bash ssh -vvv user@server_ip ``` **关键日志分析**: ```log debug1: Authentications that can continue: publickey # 服务端支持公钥认证 debug1: Next authentication method: publickey debug1: Offering public key: /home/user/.ssh/id_rsa # 客户端尝试发送私钥 debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey # 服务端拒绝密钥 debug1: Trying private key: /home/user/.ssh/id_ecdsa # 尝试其他密钥 ... debug1: No more authentication methods to try. user@server_ip: Permission denied (publickey). # 最终失败 ``` --- ### **2. 客户端密钥检查** ```bash # 检查密钥文件是否存在 ls -l ~/.ssh/id_* # 验证私钥格式(无输出即正确) ssh-keygen -y -f ~/.ssh/id_rsa > /dev/null ``` --- ### **3. 服务端公钥部署验证** ```bash # 登录服务器检查authorized_keys cat ~/.ssh/authorized_keys # 确认公钥指纹匹配(客户端执行) ssh-keygen -lf ~/.ssh/id_rsa.pub # 客户端指纹 ssh user@server_ip "ssh-keygen -lf ~/.ssh/authorized_keys" # 服务端指纹 ``` --- ### **4. 权限配置检查** **服务端关键权限**: ```bash chmod 700 ~/.ssh # 目录权限 chmod 600 ~/.ssh/authorized_keys # 公钥文件权限 chmod 755 ~ # HOME目录需可执行 ``` **错误权限示例**: ```log Authentication refused: bad ownership or modes for directory /home/user ``` --- ### **5. 服务端SSH配置检查** 编辑 `/etc/ssh/sshd_config`: ```ini PubkeyAuthentication yes # 启用公钥认证 AuthorizedKeysFile .ssh/authorized_keys # 公钥路径 PasswordAuthentication no # 建议关闭密码登录 ``` **重载服务**: ```bash sudo systemctl reload sshd ``` --- ### **6. 高级排查工具** ```bash # 服务端实时日志监控 sudo tail -f /var/log/auth.log # Ubuntu/Debian sudo tail -f /var/log/secure # CentOS/RHEL # 强制使用指定密钥 ssh -i ~/.ssh/id_rsa -v user@server_ip ``` --- ### **常见错误原因** 1. **权限问题**(70%案例):`.ssh` 目录或 `authorized_keys` 权限过宽 2. **路径错误**:公钥未正确追加到 `authorized_keys`(注意换行符) 3. **配置覆盖**:`sshd_config` 中 `AllowUsers` 限制或 `Match` 块覆盖设置 4. **SELinux干扰**(CentOS/RHEL): ```bash sudo restorecon -Rv ~/.ssh # 修复安全上下文 ``` --- ### **排查流程图** ```mermaid graph TD A[客户端 ssh -vvv] --> B{日志显示密钥发送?} B -->|否| C[检查客户端密钥文件] B -->|是| D{服务端authorized_keys存在?} D -->|否| E[部署公钥] D -->|是| F{权限是否正确?} F -->|否| G[chmod 700/600] F -->|是| H{sshd_config配置} H -->|错误| I[修改配置并重载] H -->|正确| J[检查SELinux/AppArmor] ``` --- ### **典型错误解决方案** **错误:`Agent admitted failure to sign using the key`** ```bash ssh-add ~/.ssh/id_rsa # 将密钥添加到ssh-agent ``` **错误:`no such identity`** ```bash # 确认密钥路径正确 ssh -i /path/correct_key user@server_ip ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值