git ssh 已配置公钥,但仍然无法连接成功 - lay

news/2025/10/23 14:14:53/文章来源:https://www.cnblogs.com/lay-zon/p/19160456

背景

在Raspberry Pi 上通过 git clone ssh://xxx@<host_name>:29418/<REPOSITORY_NAME.git> 克隆 Gerrit 仓库时失败,报错 Permission denied (publickey);

但使用 git@ 格式(如 git clone git@<host_name>:<REPOSITORY_NAME.git>)可成功克隆。

另一台机器使用相同的 ssh:// 格式却能正常连接。

排查步骤

  • 验证 URL 格式

确认 ssh:// 格式的用户名(layton.ren)、端口(29418)、仓库路径正确,与 git@ 格式一致。

  • 测试 SSH 连接

通过 ssh -p 29418 xxx@<host_name> -v 查看调试日志,发现关键错误:send_pubkey_test: no mutual signature algorithm(客户端与服务器无共同支持的签名算法)。

pi@raspberrypi:~ $ ssh -p 29418 xxx@<host_name> -v
OpenSSH_9.2p1 Debian-2+deb12u5, OpenSSL 3.0.17 1 Jul 2025
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to <host_name> [<host_name>] port 29418.
debug1: Connection established.
debug1: identity file /home/pi/.ssh/id_rsa type 0
debug1: identity file /home/pi/.ssh/id_rsa-cert type -1
debug1: identity file /home/pi/.ssh/id_ecdsa type -1
debug1: identity file /home/pi/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/pi/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/pi/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/pi/.ssh/id_ed25519 type -1
debug1: identity file /home/pi/.ssh/id_ed25519-cert type -1
debug1: identity file /home/pi/.ssh/id_ed25519_sk type -1
debug1: identity file /home/pi/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/pi/.ssh/id_xmss type -1
debug1: identity file /home/pi/.ssh/id_xmss-cert type -1
debug1: identity file /home/pi/.ssh/id_dsa type -1
debug1: identity file /home/pi/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.2p1 Debian-2+deb12u5
debug1: Remote protocol version 2.0, remote software version GerritCodeReview_3.2.2 (APACHE-SSHD-2.4.0)
debug1: compat_banner: no match: GerritCodeReview_3.2.2 (APACHE-SSHD-2.4.0)
debug1: Authenticating to <host_name>:29418 as 'xxx'
debug1: load_hostkeys: fopen /home/pi/.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: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: ecdh-sha2-nistp256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:wLrwyxq0wXunwomNExZCRLqJHt7HMCjIQKawgMTQUU0
debug1: load_hostkeys: fopen /home/pi/.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: Host '[<host_name>]:29418' is known and matches the ED25519 host key.
debug1: Found key in /home/pi/.ssh/known_hosts:1
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: Will attempt key: /home/pi/.ssh/id_rsa RSA SHA256:p5FNVbVuIBEww6El0FBZXhSuJe4ku2oRqR1Wgl1duMg
debug1: Will attempt key: /home/pi/.ssh/id_ecdsa
debug1: Will attempt key: /home/pi/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/pi/.ssh/id_ed25519
debug1: Will attempt key: /home/pi/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/pi/.ssh/id_xmss
debug1: Will attempt key: /home/pi/.ssh/id_dsa
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/pi/.ssh/id_rsa RSA SHA256:p5FNVbVuIBEww6El0FBZXhSuJe4ku2oRqR1Wgl1duMg
debug1: send_pubkey_test: no mutual signature algorithm
debug1: Trying private key: /home/pi/.ssh/id_ecdsa
debug1: Trying private key: /home/pi/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/pi/.ssh/id_ed25519
debug1: Trying private key: /home/pi/.ssh/id_ed25519_sk
debug1: Trying private key: /home/pi/.ssh/id_xmss
debug1: Trying private key: /home/pi/.ssh/id_dsa
debug1: No more authentication methods to try.
xxx@<host_name>: Permission denied (publickey).
pi@raspberrypi:~ $
  • 对比成功机器的日志

另一台机器(OpenSSH_7.6p1)使用 RSA 密钥时,服务器接受 ssh-rsa 算法(Server accepts key: pkalg ssh-rsa),而 Raspberry Pi 的新版 OpenSSH 默认禁用了 ssh-rsa,导致不兼容。

解决办法

- 方法一: 生成并使用其他密钥算法

例如,debug log中所提示的ecdsa、ecdsa_sk、ed25519、ed25519_sk、xmss。以ed25519为例

  • 生成 ED25519 密钥:
ssh-keygen -t ed25519 -C "your_email@example.com"
  • 将公钥(~/.ssh/id_ed25519.pub)添加到 Gerrit 账户的 SSH Public Keys 配置中。
  • 重新克隆仓库。

- 方法二:配置新版 OpenSSH 兼容 RSA 算法

若需保留 RSA 密钥,可在 ~/.ssh/config 中将配置 host 强制启用 ssh-rsa 算法:

Host <host_name>Port 29418PubkeyAcceptedAlgorithms +ssh-rsaHostKeyAlgorithms +ssh-rsa

或者可配置所有 host 均强制启用 ssh-rsa 算法:

Host *Port 29418PubkeyAcceptedAlgorithms +ssh-rsaHostKeyAlgorithms +ssh-rsa

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/944245.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2025年10月国内北京黄金回收公司全景解析报告,基于专业测评的技术、性能及市场优势深度分析

随着黄金市场的持续活跃,黄金回收行业逐渐成为消费者关注的焦点。为帮助用户精准选择可靠的服务商,本文基于企业资质、检测技术、服务透明度、客户口碑等维度,对北京地区主流黄金回收公司进行深度调研,并结合行业数…

如何安装与设置IFR02雨量传感器 接线 参数设置

如何安装与设置IFR02雨量传感器 接线 参数设置IFR02型红外雨量传感器具备多种输出类型,包括数字信号(RS232或RS485可选)、脉冲信号(支持高电平或低电平模式)以及LED状态指示灯。用户可通过配套软件灵活配置,独立…

在linux上安装kafka,并使用kafka-clients构建消费者

在linux上安装kafka,并使用kafka-clients构建消费者pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas&quo…

2025年10月国内防水耳机生产厂家全景解析报告,基于专业测评的技术、性能及市场优势深度分析

随着消费者对运动与户外活动需求的增加,防水耳机市场迎来快速增长。根据行业数据显示,2025年全球防水耳机市场规模预计突破50亿美元,年复合增长率达12%以上。本报告基于专业市场调研与产品测评数据,从技术研发、性…

Oracle故障处理:ORA-00600: internal error code, arguments: [3020], [5], [13], [20971533]

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢! 由于博客中有大量代码,通过页面浏览效果更佳。Oracle故障处…

2025年10月国内环保悬浮拼装地板生产厂家全景解析报告,基于专业测评的技术、性能及市场优势深度分析

随着环保意识的提升和体育设施建设的快速发展,环保悬浮拼装地板作为一种可回收、耐用的地面材料,在校园、体育馆和公共场所的应用日益广泛。其市场需求逐年增长,据行业数据显示,2024年全球悬浮拼装地板市场规模预计…

批量跑脚本后自定义消息内容发送至钉钉--自定义发送到钉钉的消息内容

import requestsimport jsonimport osimport timeimport sysdef send_dingtalk_message(webhook_url, success_count, fail_count, fail_module, job_name, build_number, build_user, build_url): ""&qu…

2025年10月国内四氟电加热器生产厂家全景解析报告,基于专业测评的技术、性能及市场优势深度分析

在工业加热设备领域,四氟电加热器因耐腐蚀、防粘附、高温稳定性等特性,已成为化工、医药、食品等高标准行业的首选设备。据《2025中国工业加热设备技术白皮书》统计,四氟电加热器国内市场年增长率达12.8%,其中具备…

Python编程:类型转换与输入输出

Python编程:类型转换与输入输出在Python编程中,类型转换和输入输出是基础且重要的概念。下面我将详细介绍这些内容,并提供一个综合示例。 输入输出基础 输入函数:input() input() 函数用于从用户获取输入,返回的是…

088_尚硅谷_switch使用细节(2)

088_尚硅谷_switch使用细节(2)1.switch 后也可以不带表达式, 类似多个if--else分支使用_案例演示1 2.switch 后也可以不带表达式, 类似多个if--else分支使用_案例演示2 3.switch 后也可以直接声明或定义一个变量,分号…

微软修复CVSS 10.0分高危Entra ID漏洞CVE-2025-55241 - 教程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

iText Core生成pdf的一个简单示例

使用pdfwriter创建writer对象,使用document创建文档:// 创建新的PDF文档PdfWriter writer = new PdfWriter("order_report.pdf");PdfDocument pdfDoc = new PdfDocument(writer);Document document = new …

在IntelliJ IDEA中采用Git

在IntelliJ IDEA中采用Gitpre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", &…

国产化Excel开发组件Spire.XLS教程:在Python中将Pandas DataFrame导出到Excel的详细教程

在 Python 开发中,处理表格数据是非常常见的任务,而 Pandas 是最常用的数据处理和分析库。开发者经常需要将 Pandas DataFrame 导出到 Excel,以便进行报告、团队协作或进一步的数据分析。本教程介绍如何在Python中使…

2025 年化工塑料桶生产厂家最新推荐榜:聚焦企业专利技术、品质管控及知名客户合作案例的权威解析

在化工、食品、医药等工业领域,塑料包装容器的质量直接关系到物料储存安全与运输效率。根据2025年最新行业调研数据,化工塑料桶市场规模已达187亿元,年均增长率5.8%。本文基于对企业产能规模、工艺专利数量、质检合…

主流CI/CD工具选型指南:助力企业实现高效交付

DevOps工具选型指南:Gitee CI/CD如何助力企业实现高效交付 在数字化转型浪潮中,DevOps已成为企业提升软件交付效率的核心方法论。作为DevOps实践的关键环节,持续集成与持续交付(CI/CD)工具的选择直接影响着企业的…

通过openwrt唤醒pc电脑

参考 https://todesk.com/helpcenter/questions-86.html 重点 网卡设置 在网卡的电源设置中,最好不要勾选准许计算机关闭此设备以节约电源 ARP绑定 局域网唤醒如果是局域网唤醒pc,完全不需要ARP绑定 比如通过openwrt…

图表控件Aspose.Diagram教程:在C#中将VSD转换为PDF

Microsoft Visio 使用VSD文件来保存专业图表、流程图和业务流程模型。但是,如果收件人未安装 Microsoft Visio,则共享 VSD 格式的 Visio 图表可能会效率低下。一种通用且便携的共享图表的方法,同时保持格式和布局不…

Gitee:中国开发者生态的数字化转型引擎

Gitee:中国开发者生态的数字化转型引擎 在中国数字经济高速发展的背景下,本土化代码托管平台正成为企业数字化转型的关键基础设施。Gitee作为国内领先的一站式DevOps平台,凭借其深度本地化服务、全流程开发工具链和…