Jenkins: what is the correct format for private key in Credentials

萝らか妹 提交于 2019-11-26 05:27:05

Check the version of Git for Windows that you are using: Starting 2.19.2, it comes with OpenSSH v7.9p1 (from 7.7 before)

And... openssh 7.8 just changed the default ssh-keygen format, from a classic PEM 64-chars, to an OPENSSH one 70 chars!

Only ssh-keygen -m PEM -t rsa -P "" -f afile would generate the old format (-m PEM)

ssh-keygen(1):

write OpenSSH format private keys by default instead of using OpenSSL's PEM format.

The OpenSSH format, supported in OpenSSH releases since 2014 and described in the PROTOCOL.key file in the source distribution, offers substantially better protection against offline password guessing and supports key comments in private keys.
If necessary, it is possible to write old PEM-style keys by adding "-m PEM" to ssh-keygen's arguments when generating or updating a key.

In the end, I couldn't find a way to make pasting private keys to Jenkins credentials work.

While it might common knowledge for many, I decided to put the workaround below anyway.

Here is what I did as a workaround to pull my private repositories from Bitbucket.org:

  1. Log in to your Windows host as the user which runs Jenkins Service. In my case, Jenkins Service runs as a dedicated user because I needed to access network shares with write privileges restricted to this user only.
  2. Open Git-bash and generate SSH keys with ssh-keygen command accepting all defaults
  3. In Jenkins, enter the git repo URL as git@bitbucket.org:team_name/repo_name and leave the credentials as None

This way Git and SSH will be able to find SSH keys in the default location, which usually is c:\Users\username.ssh\

Hope this helps somebody.

I also got this error message and eventually found out that the Jenkins credential should be RSA secret key, not public key. Below is my steps for configuring Jenkins to clone from bitbucket:

  1. Add credential in Jenkins credentials
   Kind: SSH username and private key
   Scope: Global
   Username: <my username in bitbucket>
   Private key: <Enter directly>
         -----BEGIN RSA PRIVATE KEY-----
         ......
         -----END RSA PRIVATE KEY-----
  1. Create a job and configure the repository path and credential as following:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!