记一次奇怪的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之后果然即可成功登录。

相关推荐
H_oRIZoN_33 分钟前
Linux入门DAY41(51 单片机 串口与通信协议)
linux·运维·单片机
小马同学-2 小时前
OpenStack 使用实战:Web 界面与 CLI 命令行实验
运维·云计算·openstack
网安老伯3 小时前
都2026年了,还在问网络安全怎么入门?看完这一篇你就懂了
运维·计算机网络·web安全·网络安全·wireshark·密码学·网络攻击模型
小祺先生3 小时前
mt7921 debian系统 如何安装驱动
运维·网络·debian
m0_459872924 小时前
Linux 系统基础
linux·运维·服务器
fb_123454 小时前
Docker入门-第3章-容器镜像深度解析
运维·docker·容器
吴声子夜歌4 小时前
Shell编程——数组
linux·运维·shell
2401_891957314 小时前
简单了解多路转接select
运维·服务器
2302_1114 小时前
java依赖小结
java·运维·数据库
程序员-Benothing5 小时前
Shell 脚本条件判断与流程控制:if for while case 详解
linux·运维·服务器