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

相关推荐
HoneyMoose19 小时前
Jenkins 构建 VUE 前端提示 pnpm 错误
前端·vue.js·jenkins
Warren9820 小时前
Windows 本地安装 Jenkins 教程
linux·运维·windows·功能测试·mysql·jenkins
LuDvei2 天前
windows x86中ssh远程连接 ubuntu
windows·ubuntu·ssh
程序人生5182 天前
ubuntu桌面版安装后配置允许root通过图形界面登录和ssh登录 亲测有效
ubuntu·postgresql·ssh
玄奕子2 天前
VS Code 上传 GitHub 全流程(Windows 环境):HTTP 与 SSH 两种方案(含常见报错排查)
git·http·ssh·github·嵌入式开发
渣渣馬2 天前
shell的if多条件
git·ssh
vortex52 天前
构建可审计、可分层、可扩展的SSH身份管理体系
网络·ssh·php
芜湖xin4 天前
【恒源智享云】pycharm社区版SSH方式使用实例
ssh·云服务器
corpse20104 天前
VirtualBox 安装ubuntu-25 ,配置SSH工具登录
linux·ubuntu·ssh
safestar20124 天前
ES批量写入性能调优:BulkProcessor 参数详解与实战案例
java·大数据·运维·jenkins