Pra*_*ash 2 ssh jenkins jenkins-pipeline
为了使用 ssh 将 jenkins 与远程服务器连接,我在 jenkins 中安装了通过 SSH 插件发布。但在配置后,它显示错误为 jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key。消息[无效私钥:[B@7934add]
最初我在服务器中以 jenkins 用户身份登录为“sudo su jenkins”之后,我输入了“ssh-keygen”并给出了密码值并给出了 jenkins 配置中的密钥路径。
我的密码是我在创建 ssh-keygen 时给出的值
我的密码短语/密码与我在创建 ssh-keygen 时给出的值相同。我对这一点不正确
但是当我单击测试配置按钮时,我的所有配置都显示“
Failed to connect or change directory
jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key. Message [invalid privatekey: [B@3085b39b]"
Run Code Online (Sandbox Code Playgroud)
关键路径应该是路径私有密钥id_rsa
。
不是公开的id_rsa.pub
(这确实是一个无效的......私钥)
创建 SSH 密钥对已生成:
/var/lib/jenkins/.ssh/id_rsa
(私钥)/var/lib/jenkins/.ssh/id_rsa.pub
(公钥)ssh-keygen -t rsa -C "jenkins" -m PEM -P "" -f /var/lib/jenkins/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)
要打开 SSH 会话,需要将公钥复制到远程服务器,以/home/ubuntu/.ssh/authorized_keys
.
如果您有远程 ubuntu 用户密码,则可以使用ssh-copy-id 命令,如下所示:
ssh-copy-id -i /var/lib/jenkins/.ssh/id_rsa ubuntu@remoteserverip
Run Code Online (Sandbox Code Playgroud)
然后你可以测试,作为sudo su jenkins
,连接ssh -Tv ubuntu@remoteserverip
您需要以 Jenkins 用户的身份在 Jenkins 服务器上创建一个公钥/私钥,然后将公钥复制给您想要在目标服务器上进行部署的用户。
步骤1,以jenkins用户身份在构建服务器上生成公钥和私钥
build1:~ jenkins$ whoami
jenkins
build1:~ jenkins$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa):
Created directory '/var/lib/jenkins/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa.
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub.
The key fingerprint is:
[...]
The key's randomart image is:
[...]
build1:~ jenkins$ ls -l .ssh
total 2
-rw------- 1 jenkins jenkins 1679 Feb 28 11:55 id_rsa
-rw-r--r-- 1 jenkins jenkins 411 Feb 28 11:55 id_rsa.pub
build1:~ jenkins$ cat .ssh/id_rsa.pub
ssh-rsa AAAlskdjfalskdfjaslkdjf... jenkins@myserver.com
Run Code Online (Sandbox Code Playgroud)
第2步,将pub文件内容粘贴到目标服务器上。
target:~ bob$ cd .ssh
target:~ bob$ vi authorized_keys (paste in the stuff which was output above.)
Make sure your .ssh dir has permissoins 700 and your authorized_keys file has permissions 644
Run Code Online (Sandbox Code Playgroud)
第三步,配置Jenkins
In the jenkins web control panel, nagivate to "Manage Jenkins" -> "Configure System" -> "Publish over SSH"
Either enter the path of the file e.g. "var/lib/jenkins/.ssh/id_rsa", or paste in the same content as on the target server.
Enter your passphrase, server and user details, and you are good to go!
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8002 次 |
最近记录: |