一. 安装SSH Plugin插件

在这里插入图片描述

二. 添加Credentials

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

三. 远程主机SSH配置

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四. 免密登录

jenkins免密登录其他服务器

  1. 在jenkins后台生成公钥、私钥对
[root@jenkins3 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:4bwSPBMDqt1mIGJyOYpXhERIWE804ZDsdDQDDd3BR7s root@jenkins3
The key's randomart image is:
+---[RSA 2048]----+
|oBBX@+.o.        |
|o =O+=o ..       |
|++*.+ o.o        |
|=*.= . = o       |
|+ o + = E        |
| . o   + .       |
|      . .        |
|       .         |
|                 |
+----[SHA256]-----+
[root@jenkins3 ~]# 


  1. 添加凭据-告诉jenkins自己的私钥是什么,jenkins将用这个私钥和对方服务器进行免秘钥认证

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述在这里插入图片描述
3. 将jenkins的公钥复制到对方服务器的authorized_keys

[root@jenkins3 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.30.9
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.30.9's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.30.9'"
and check to make sure that only the key(s) you wanted were added.
  1. 在jenkins上配置登录192.168.30.9这台服务器时使用免密登录

在这里插入图片描述

在这里插入图片描述

  1. 在jenkins后台将自己的私钥复制到jenkins目录
[root@jenkins3 ~]# cp /root/.ssh/id_rsa /var/lib/jenkins/

五. 在构建项目中ssh远程主机时使用这个远程主机

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐