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

相关推荐
dyxal41 分钟前
内网windows系统机器通过vscode ssh连接内网服务器,无网络导致的一系列无法正常连接问题
服务器·vscode·ssh
qq_3391911415 小时前
aws ec2防ssh爆破, aws服务器加固, 亚马逊服务器ssh安全,防止ip扫描ssh。 aws安装fail2ban, ec2配置fail2ban
服务器·ssh·aws
测试开发Kevin17 小时前
详解Jenkins 的 Declarative Pipeline中post 语法
jenkins·devops
北城笑笑1 天前
Git 10 ,使用 SSH 提升 Git 操作速度实践指南( Git 拉取推送响应慢 )
前端·git·ssh
蓁蓁啊1 天前
GIT使用SSH 多账户配置
运维·git·ssh
一张假钞2 天前
Jenkins 项目迁移
ci/cd·jenkins
等风来不如迎风去2 天前
用你本地已有的私钥(private key)去 SSH 登录远程 Ubuntu 服务器
服务器·ubuntu·ssh
软件测试君2 天前
Jenkins Share Library教程 —— 开发入门
jenkins
万山y2 天前
WSL SSH 服务器一站式配置教程
运维·服务器·ssh
Broken Arrows3 天前
如何在Linux服务器上部署jenkins?
linux·jenkins