I'm creating a task on Jenkins version 2.235.1 on a computer using Ubuntu version 18.04.3 LTS to do CD using a repo on Github. I have it all working using username and password to log on Github.
The issue is that GitHub is no longer going to support username and password connection and I will need to connect by ssh username with private key. I tried the process following all the necessary steps and I still can't manage to connect.
I'm gonna carefully elaborate the steps of connection. Hopefully, someone can tell me what I'm doing wrong.
I have created an id_rsa for a user called Jenkins using this command:
ssh-keygen -t rsa -b 4096 -C "my_github@email.com"
with a passphrase “my_passphrase”
I have placed the public key on Github to the user “user_name” (The owner of the repo)
This works, since I can execute the following command from the server:
git ls-remote -h -- git@github.com:user_name/proyect_name.git
After asking me for my passphrase it returns all repo branches. So my public key and private key are working correctly.
Next step is setting credentials on Jenkins to connect to Github. I'm setting my credentials like so:
Kind: SSH username with the private key
Scope: Global
Id: empty
Description: empty
Username: user_name (owner on GitHub that has a public key assigned)
Private key: <Enter directly>
-----BEGIN RSA PRIVATE KEY-----
......
-----END RSA PRIVATE KEY-----
Passphrase: my_passphrase
Im copying the private key using CAT, dragging, selecting until the last dash and doing control+shift+c.
Im placing the URL of the GitHub repo like this:
git@github.com:user_name/proyect_name.git
When it tries to connect it throws the following error:
Failed to connect to repository :
Command "git ls-remote -h -- git@github.com: user_name/proyect_name.git HEAD"
returned status code 128:
stdout:
stderr: git@github.com: Permission denied (public key).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Could it be that I'm not pasting the private key correctly??
Thanks very much in advance, any help will be greatly appreciated.
Jorge