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

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


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.


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:

enter image description here


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.