We use SSH keys on jenkins to clone from our remote Git. It works fine. We use the git plugin, use credentials for SSH and we are able to clone the repo.
But when we execute the following command in a later stage it fails:
git pull origin master
It complains about:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
It seems like this command isn't using our SSH credentials anymore. How can we use the git CLI to keep our SSH credentials?
I've seen the answer here but it seems another case then what we are facing.
+
cat .git/config
[core]
repositoryformatversion = 0
filemode = true
logallrefupdates = true
[remote "origin"]
url = ssh://git@xxx/test-repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
First check your existing SSH keys:
Open Git Bash.
Enter ls -al ~/.ssh
to see if existing SSH keys are present:
$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
Check the directory listing to see if you already have a public SSH key.
If there is an existing SSH key test your SSH connection:
Open Git Bash.
Enter the following:
$ ssh -T [email protected]
# Attempts to ssh to GitHub
You may see one of these warnings:
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
Verify that the fingerprint in the message you see matches one of the messages in step 2, then type yes:
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
Verify that the resulting message contains your username. If you receive a "permission denied" message, see "Error: Permission denied (publickey)".
If the above process doesn't work:
generate SSH key to your git repository steps:
Open Git Bash.
Paste the text below, substituting in your GitHub email address.
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
This creates a new ssh key, using the provided email as a label.
Generating public/private rsa key pair.
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Adding a new SSH key to your git repository visit here,
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With