jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key
2020-04-30jenkins无密码ssh时报错:jenkins.plugins.publish_over.BapPublisherException: Failed to add SSH key. Message [invalid privatekey: [B@6a581993]
com.jcraft.jsch.JSchException: invalid privatekey, 部分库(如:JSch)不支持OPENSSH PRIVATE KEY格式的私钥
1、jenkins使用 ssh-keygen -m PEM -t rsa -b 4096 来生成key就可以用了。
-m 参数指定密钥的格式,PEM(也就是RSA格式)是之前使用的旧格式
2、如果ssh-keygen -t rsa 默认产生的key 2048位
需要用puttygen.exe导出为openssl格式
3、放到/data/1jenkins2048
chown jenkins.jenkins 1jenkins2048
4、id_rsa.pub放到远端的authorized_keys文件里面
5、openssl rsa -in 1jenkins2048 -noout -text
Enter pass phrase for 1jenkins2048:
RSA Private-Key: (2048 bit, 2 primes)
6、假设有OPENSSH PRIVATE KEY格式文件:demo.private
load文件:puttygen demo.private
导出为RSA PRIVATE KEY格式:Conversions -> Export OpenSSH key
转换为ppk格式:
`puttygen tempkey -o tempkey.ppk`
转换回openssh格式:
`puttygen tempkey.ppk -O private-openssh -o tempkey.oldformat`
7、# generate ssh.com private key from private openssh key
$ puttygen newkey -O private-sshcom -o newkey.puttygen-sshcom
# generate ssh.com public key from private openssh key
$ puttygen newkey -O public -o newkey.pub_puttygen-sshcom
# generate openssh public key from private openssh key (for confirmation)
$ puttygen newkey -O public-openssh -o newkey.pub_puttygen-openssh