Reputation: 31
I am facing this problem for a very long now.I am able to ssh clone the repo and commit to the same repo, but when try mvn clean release:clean release:prepare release:perform
the build is failing as below.
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] [email protected]: Permission denied (publickey).
[ERROR] fatal: Could not read from remote repository.
[ERROR]
[ERROR] Please make sure you have the correct access rights
[ERROR] and the repository exists.
The thing is when I try to mvn clean release:clean release:prepare release:perform
it should use [email protected]
instead of [email protected]
. Can someone please help me resolve this ?
Upvotes: 2
Views: 3454
Reputation: 384
SSH keys let you authenticate with a Git repository without worrying about passwords. SSH is the same method of authentication that Linux servers use to allow remote access.
SSH keys rely on public-private key authentication. For this method of authentication to work, your Git server must be configured with a public key, and your local machine must have the corresponding private key.
Git clients like Atlassian and GitHub require that you upload your public key to their dashboards before you can use SSH authentication.
An Example Scenario
We’ve configured a local repository called ck-git. This repository contains one file: README.md.
We are going to link this repository to one on GitHub. To do this, we can use the git remote command:
git remote add origin [email protected]:career-karma-tutorials/ck-git.git
We have created a remote called “origin” to which we can push our code. To push our local repository to GitHub, we can use the git push command:
git push -u origin master
This command uploads our changes to the master branch on our “origin” remote server. Let’s see what happens when we run the command:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
We have encountered an error.
Solution #1:
Check that your key is used Before we explore any other solutions, we should make sure that our key is being used to make an SSH connection. We can do this by using the ssh-add command:
eval "$(ssh-agent -s)" ssh-add -l -E md5 The first command starts the SSH agent on your computer. The next command lists all of the SSH keys that are configured on your machine.
Now that you have this list of SSH keys, check to see if they match the one you’ve uploaded to GitHub, Bitbucket, or another version control system you use. If at least one of the keys on the list does not match, you need to add one of them to your version control system.
Solution #2
: Adding an SSH key You may encounter this error if you have not yet added an SSH key to your version control account. The way in which you add an SSH key to a Git repository varies depending on the version control system you use.
For GitHub, you can use the following steps:
Note down your SSH key using the commands we discussed in Solution #1
Open GitHub, click on your avatar on the top-right corner and click “Settings”
Click “SSH and GPG keys” in the sidebar
Add an SSH key to your account
To add an SSH key to your account, you must first have a key. You can generate one using the following commands:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh-add -K ~/.ssh-/id_rsa
Substitute “id_rsa” for the name of your key if you changed it when you were prompted to choose a key name from the first command.
Then, run the following command to see your public key:
cat ~/.ssh/id_rsa.pub
This will give you the string you need to upload into your version control system.
Cause #3: Using the wrong method of authentication We’ve configured our repository to use an SSH URL:
git remote add origin [email protected]:career-karma-tutorials/ck-git.git
Using this URL means we must use SSH authorized key pairs to authenticate with our repository.
This is only possible if we have set up SSH authentication. If you want to configure your repository with HTTP, which lets you use a username and password to authenticate, you must use an HTTP URL:
git remote add origin https://github.com/career-karma-tutorials/ck-git
When we push our code to our remote server, we’ll be asked for our Git username and password. This will give us a chance to authenticate using HTTP instead of SSH.
Conclusion
The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository.
To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git. If you do not have a public key and want to use one to authenticate with Git, you’ll need to create one.
You may want to opt to authenticate using HTTP if you do not want to use SSH. You can do this by using a HTTP URL as the remote URL for your repository.
ref :https://git-scm.com/docs/git-push
Upvotes: 1
Reputation: 1327384
One workaround to test would be:
git config --global [email protected]:.insteadOf [email protected]:
(assuming an SSH URL using :
in it)
That way, Git would be forced to use the right user in its SSH URL.
Upvotes: 2