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

相关推荐
袁袁袁袁满20 小时前
Linux网络连接之ss命令详细使用指南(从入门到运维实战)
linux·运维·服务器·网络·ssh·网络连接·ss命令
迎仔1 天前
10-算力中心运维三剑客:Ansible + Jenkins + K8s 高效实战
运维·kubernetes·ansible·jenkins
weixin_531651811 天前
Elasticsearch 检索原理分析
大数据·elasticsearch·jenkins
Web极客码2 天前
用 SSH Key 认证提升文件传输安全:SFTP/SSH 加固实战(适合站点运维与外贸站)
运维·安全·ssh
海兰2 天前
Elasticsearch 9.3.0 日志数据源配置
大数据·elasticsearch·jenkins
jimy12 天前
从Windows terminal里面的输出内容中截取trim IP 地址,再更新到.ssh/config文件里面
windows·tcp/ip·ssh
海兰2 天前
elasticsearch学习之基本概念-混合搜索
学习·elasticsearch·jenkins
fjh19972 天前
记一次奇怪的ssh公钥登录失败的情况
运维·ssh
何中应3 天前
使用Jenkins部署前端项目(Vue)
前端·vue.js·jenkins
何中应3 天前
使用Jenkins部署后端项目(Maven)
运维·ci/cd·jenkins