为了通过ssh将jenkins与远程服务器连接,我在jenkins中安装了通过SSH插件发布。但是配置后,它将显示为jenkins.plugins.publish_over.BapPublisherException错误:无法添加SSH密钥。消息[无效私钥:[B @ 7934add]
最初,我在服务器上以jenkins用户身份登录为“ sudo su jenkins” 之后,我键入“ ssh-keygen”并给出密码短语的值,并给出詹金斯配置中的密钥路径。
我的密码短语是我在创建ssh-keygen时给出的值
我的密码/密码与我创建ssh-keygen时给出的值相同。我对这一点不正确
但是当我单击“测试配置”按钮时,我的所有配置都显示为“
Charles -headless
答案 0 :(得分:1)
密钥的路径应为私有密钥friend_ids
的路径。
不是公用的id_rsa
(确实是无效的...私钥)
创建SSH密钥对已生成:
id_rsa.pub
(私钥)/var/lib/jenkins/.ssh/id_rsa
(公共密钥)要打开SSH会话,需要将公用密钥复制到/var/lib/jenkins/.ssh/id_rsa.pub
中的远程服务器上。
如果您具有远程ubuntu用户密码,则可以将ssh-copy-id command用作seen here:
/home/ubuntu/.ssh/authorized_keys
然后,您可以以ssh-copy-id -i /var/lib/jenkins/.ssh/id_rsa ubuntu@remoteserverip
的身份测试与sudo su jenkins
的连接
答案 1 :(得分:0)
您将需要在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
第2步,将发布文件的内容粘贴到目标服务器上。
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
第3步,配置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!
答案 2 :(得分:0)
MacOS似乎使用了一种更新的技术来生成密钥。
使用-m PEM
生成密钥为我解决了这个问题。
完整的呼叫是:ssh-keygen -t rsa -b 4096 -m PEM
,然后按照Prakash所说的步骤进行操作。