Bitbucket/Github: permission denied public key
Asked Answered
G

6

4

when I am trying to clone a rails app repo I have got permission to, I am getting this issue.

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Even after adding public key by generating one, I am unable to solve this.

Although I am able to clone using he https method but after making changes, the same error comes while I try to push the code.

Please suggest an answer for this.

Gaillardia answered 3/11, 2015 at 4:36 Comment(2)
try running eval $(ssh-agent)Minelayer
Agent pid 6108 This is what it givesGaillardia
J
11

First, cd into your .ssh directory. Open up the terminal and run:

cd ~/.ssh && ssh-keygen

Second, you need to copy this to your clipboard:

 cat id_rsa.pub | pbcopy # On OSX
 cat id_rsa.pub | xclip # On Linux

Third, add your newly generated ssh key to your account via the github/bitbucket website (just paste there).

Next, setup your git config:

git config --global user.name 'your_user_name'
git config --global user.email 'your_email'

Finally, restart your command line to make sure the config is reloaded.

Now, you should be able to clone and push from/to your github repository.

For more information on this, see this github page or this bitbucket page.

Janus answered 3/11, 2015 at 6:34 Comment(1)
Doesn't work for me. It gives the same message. May be would help to know how to use particular ssh key, and how not to use the global git config. Also I don't understand how setting the global config helps for git to find which one of all SSH keys to use when I have like more than 2.Delouse
B
5

When attempting to clone, push, or pull over SSH with Git, you may receive one of these messages if Bitbucket couldn't authenticate with the keys that your SSH agent offered.

Here are the most common reasons why you may see these messages:

You used sudo when attempting the connection

You shouldn't use sudo when cloning, pushing, or pulling because the ssh-agent runs on the user level, not the root level.

Your public key isn't loaded into Bitbucket

To check if your public key is loaded into Bitbucket, do the following:

From Bitbucket, choose Personal settings from your avatar in the lower left. The Account settings page displays.

Click SSH keys. The SSH keys page shows a list of any existing keys.

If you don't have any keys listed, you can follow our Set up an SSH key documentation to set one up.

Your key isn't loaded into your SSH agent

If your SSH agent doesn't know to offer Bitbucket a key, the connection fails. You may run into this issue if you've recently restarted your system.

You can refer to this Article for more informations: https://support.atlassian.com/bitbucket-cloud/docs/troubleshoot-ssh-issues/

Basuto answered 11/2, 2022 at 8:54 Comment(0)
P
0

Check few things.

  1. Is the generated new key is the one your ssh agent using when trying to ssh to server. (Your ssh agent might be using a different key than the one you generated) use this to list currently loaded keys by agent.

    ssh-add -L

  2. You properly added public key to your repository hosting location.

The keys corresponding to above 1 and 2 should match.

Philis answered 3/11, 2015 at 4:45 Comment(0)
B
0

Please see this article: GitHub: Generating SSH Keys. What happens when you run:

ssh -T [email protected]

?

You may have added the wrong key to authenticate with.

Blade answered 3/11, 2015 at 5:36 Comment(1)
The authenticity of host 'github.com (192.30.252.129)' can't be established. I am using bitbucketGaillardia
L
0

I faced this error when I created another repository in my local. My ssh-keys were already set up and I was trying to push code through vs code. The issue got resolved when I git push-ed through git bash like I was doing before.

Lithoid answered 14/2, 2022 at 13:18 Comment(0)
D
0

For bit bucket I think I have tried everything with ssh. I have tried the answer from this stackoverflow question as well. But it doesn't work. So finally I just changed the clone command from SSH to HTTPS and it worked. Only then it asked for password for my account.
enter image description here

Delouse answered 28/9, 2022 at 6:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.