Jenkins 推送报错 - SSH 密钥失效


目录


问题描述

jenkins 构建完毕后,将构建好的 jar 包推送至远端服务器时,Deploy 阶段报如下错误:

sh 复制代码
+ sshpass -p **** scp -o StrictHostKeyChecking=no -P 22 -r /data/jenkins/workspace/TAI/TAI/AllCam-tai-cloud/tai-131-lmm/service/target/lmm.jar root@xxx.xxx.xxx.xxx:/home/lmm/app/
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:/Y24roRxGVOfviBZ/h6IKXgi7DEsDj4LDpJu6SPHq2k.
Please contact your system administrator.
Add correct host key in /var/lib/jenkins/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /var/lib/jenkins/.ssh/known_hosts:2
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.

Authorized users only. All activities may be monitored and reported.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
lost connection

报错原因

本文标题已给出 ------ "SSH 密钥失效"

先来看看 Pipeline 是怎么写的:

原因:其实 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 的问题显然就是因为目标服务器的主机密钥发生变化而,执行上图红框部分时导致的 SSH 连接报错,这是因为我重装了目标服务器操作系统(重装后 IP 不变),这就导致在 Jenkins 主机上 ~/.ssh/known_hosts 下的主机的记录失效,从而导致无法连接目标服务器。

解决方案

在每次执行发布时先执行下图红框部分指令,此时 SSH 工具会在 Known Hosts 文件中查找与 ${params.ServerIp} 匹配的条目,如果找到,SSH 工具会将该条目删除,这可以避免因为目标服务器的主机密钥发生变化而导致的 SSH 连接报错 - WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

---END

相关推荐
kishu_iOS&AI3 小时前
Git SSH + SourceTree篇
运维·git·ssh
学习使我快乐——玉祥4 小时前
ElasticSearch离线安装
大数据·elasticsearch·jenkins
H_老邪4 小时前
Docker 学习之路-从入门到放弃-Jenkins:4
容器·jenkins
Hns.5 小时前
SSH 端口转发IP请求
运维·tcp/ip·ssh
sjmaysee5 小时前
Springboot中使用Elasticsearch(部署+使用+讲解 最完整)
spring boot·elasticsearch·jenkins
新时代牛马6 小时前
Windows SSH 免密码登录 Ubuntu
运维·ubuntu·ssh
一只叫煤球的猫1 天前
[自荐] macOS 99% 原生 SSH + SFTP 工具 Remora ,现在开源了~
开源·ssh·github
阿蒙Amon1 天前
C#常用类库-详解SSH.NET
c#·ssh·.net
yuweiade1 天前
如何安装配置Goland并使用固定公网地址SSH远程连接本地服务器
运维·服务器·ssh