Jenkins中使用execute shell script on remote host using ssh
一. 安装SSH Plugin插件二. 添加Credentials三. 远程主机SSH配置四. 免密登录五. 在构建项目中ssh远程主机时使用这个远程主机
·
Jenkins中使用execute shell script on remote host using ssh
一. 安装SSH Plugin插件
二. 添加Credentials
三. 远程主机SSH配置
四. 免密登录
jenkins免密登录其他服务器
- 在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 ~]#
- 添加凭据-告诉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.
- 在jenkins上配置登录192.168.30.9这台服务器时使用免密登录
- 在jenkins后台将自己的私钥复制到jenkins目录
[root@jenkins3 ~]# cp /root/.ssh/id_rsa /var/lib/jenkins/
五. 在构建项目中ssh远程主机时使用这个远程主机
点击阅读全文
更多推荐
目录
所有评论(0)