I\'m creating a job in Jenkins 2.152 running on Windows Server 2016 which needs to pull from a git repo hosted on bitbucket.org. I tested the ssh key through git-bash so I k
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:
ssh-keygen
command accepting all defaultsNone
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:
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-----
following worked for me
Create a folder (say testkey), cd inside the folder and right click and select git bash
now create OPENSSH Key using following command in git bash. here test.key is name of your OPENSSH key (note that passphrase is optional)
ssh-keygen -f test.key
ssh-keygen -f test-pem.key -m PEM -p
Now the key is converted into PEM key, copy the content of the key using notepad.
Go Jenkins -> Credentials -> Add New Credentials.
7.Select Kind SSH Username and Key , Provide username , and paste the PEM key content copied in step 5 and paste into private key, note that passphrase is optional.
Original SSL Command Copied from GITHUB - git@github.com:test/goto.git
change it to - ssh://git@github.com/test/goto.git
Somehow I got it work again but the real steps that fix the issue is unclear.
what I did is to regenerate the ssh key again and put everything to its default location. Reupload the public key, replace the private key in the credential and then it starts to work.
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.
So just to add an answer to actually convert a key from the new OPENSSH format to the older PEM format:
$ ssh-keygen -f blah.key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in blah.key.
Your public key has been saved in blah.key.pub.
The key fingerprint is:
SHA256:ndMFvZjbD7M3MoqFy8+me74gPhcuoDVLF2/Oh+hXQ8I perbelding@erpelbook4.local
$ head -n 1 blah.key
-----BEGIN OPENSSH PRIVATE KEY-----
$ ssh-keygen -f blah.key -m PEM -p
Key has comment 'redacted'
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved with the new passphrase.
$ head -n 1 blah.key
-----BEGIN RSA PRIVATE KEY-----
ssh-keygen -p changes the passphrase but it does not mind the new passphrase being the same (even none) as the old one and in the process can convert the format.