记一次奇怪的ssh公钥登录失败的情况

配置了公钥之后提示登录失败,于是开启了-vvv模式,提示:

bash 复制代码
debug1: Offering public key: /Users/jihanfu/.ssh/id_rsa RSA SHA256:HYJ/2VQ9GbMqG8KZAHfuNlcU+j8qWeQSTi+NEZFR1Tw
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/jihanfu/.ssh/id_ecdsa
debug3: no such identity: /Users/jihanfu/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/jihanfu/.ssh/id_ecdsa_sk
debug3: no such identity: /Users/jihanfu/.ssh/id_ecdsa_sk: No such file or directory

注意到中间receive packet: type 51,收到了51,代表不接受我发送的公钥的指纹,然后我使用命令检查了一下我的私钥派生的公钥

bash 复制代码
➜  CSDN git:(main) ✗ ssh-keygen -y -f ~/.ssh/id_rsa
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCzNv9/IPwLbklJEJWdCGKPSOb/2ePExmC6/lXN2Zj+4ZcEc3hupGRB0CU736moTlDN0A8DmEHmjRnKybA4yA7uNPYLp3

居然和linux上面的~/.ssh/authorized_keys里面的内容时一样的,这就很奇怪了。公钥明明正确但不接受。

之后去问了一下gemini,gemini建议我检查一下指纹,于是我检查了一下指纹。

bash 复制代码
 CSDN git:(main) ✗ ssh-keygen -l -f <(ssh-keygen -yf ~/.ssh/id_rsa )
3072 SHA256:BrDxupUTSNIgnoX+lIpuOVoqr4K4sqL3LniG4cDImAc jihanfu@jihandeMacBook-Pro.local (RSA)

发现指纹不匹配。BrDxupUTSNIgnoX+lIpuOVoqr4K4sqL3LniG4cDImAc,但我实际发送的是HYJ/2VQ9GbMqG8KZAHfuNlcU+j8qWeQSTi+NEZFR1Tw.

之后再次问了gemini,得到一个可能性,虽然日志里面写的是读取公钥文件 Offering public key: /Users/jihanfu/.ssh/id_rsa.

但实际上读的是/Users/jihanfu/.ssh/id_rsa.pub.

之后检查了一下id_rsa.pub,果然:

bash 复制代码
➜  CSDN git:(main) ✗ ssh-keygen -l -f ~/.ssh/id_rsa.pub
3072 SHA256:HYJ/2VQ9GbMqG8KZAHfuNlcU+j8qWeQSTi+NEZFR1Tw jihanfu@jihandeMacBook-Pro.local (RSA)

这里的指纹和发送过去的对的上,所以说ssh的日志本身具有误导性,ssh在有id_rsa.pub的时候会读id_rsa.pub,没有的时候会从id_rsa文件派生。

而这个id_rsa.pub文件因为错误配置导致和id_rsa文件匹配不上了。

因此删除不一样的id_rsa.pub之后果然即可成功登录。

相关推荐
遇见小修修8 分钟前
打印机无法连接故障:操作误区汇总与排查教程
运维·服务器
Elastic 中国社区官方博客24 分钟前
使用 OpenTelemetry 在 Elastic 中实现 Claude 平台的人工智能 agent 可观测性
大数据·运维·服务器·人工智能·elasticsearch·信息可视化·全文检索
hzxxxz30 分钟前
3个模块搭稳一条自动化链路:定时任务、幂等与对账
运维·自动化
Ruiery1 小时前
Linux 6.6内核内存管理深度解析(十):KSM 同页合并 — 内容去重,把 N 份相同内存合并成 1 份
linux·运维·服务器
Huangjin007_1 小时前
【Linux 系统篇(三十三)】通信(三):System V 共享内存详解
linux·运维·服务器
叼烟扛炮1 小时前
Linux 学习笔记(三十八):从实模式到分页——处理器内存管理的发展史
linux·运维·服务器
润滑卫士1 小时前
油液水分在线传感器技术对比:电容法、电阻法与微波法的测量原理与适用性
运维
Decay__1 小时前
附-01 · MySQL 压测与容量规划 —— sysbench 基准测试、容量评估与参数基线
运维·数据库·sql·mysql·架构
mennekes2 小时前
暗装插座箱 VS 明装插座箱,工地和车间怎么取舍
运维·网络·科技·安全·制造
叼烟扛炮2 小时前
Linux 学习笔记(三十六):并发进阶——读写锁 vs 自旋锁,到底怎么选?
linux·运维·服务器·笔记·学习