Bitbucket ssh public key is being denied but their ssh test connects with no issue
Asked Answered
P

3

16

A quite probably relevant piece of information is that I have a custom ssh config set up for bitbucket. In my '.ssh/config' file I have the following:

[ivanna@comp]$ cat ~/.ssh/config 
Host bitbucket
    Hostname        bitbucket.org
    IdentityFile    /home/ivanna/.ssh/id_rsa_bitbucket
    IdentitiesOnly yes

The permissions on this file are definitely correct as far as ssh is concerned (I actively use other entries in the config file). Now when I added the remote origin in git I used bitbucket instead of bitbucket.org:

git remote add origin bitbucket:ivanna/my-repo.git

but when I try to push I get the following error:

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

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

So it seems like I didn't add my public key or something, right? But I definitely did. And when you search for more information you find this page about the error (https://confluence.atlassian.com/pages/viewpage.action?pageId=302811860). And when I do what they say to do to check the key:

[ivanna@comp]$ ssh -T hg@bitbucket
logged in as ivanna.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

It can login fine, it seems. So... why doesn't pushing work? The above link mentions that it could be a permissions issue on the project itself but I set the permissions as people suggested and it did nothing. Anybody know what's going on?

Perez answered 27/7, 2015 at 18:10 Comment(0)
C
15
ssh -T hg@bitbucket

You use hg@bitbucket when logging in via SSH, but in the remote URL you add to Git, you don’t specify a username. Since the configuration also does not include one, Git won’t know what username to log in with.

Change the URL to this:

git remote add origin git@bitbucket:ivanna/my-repo.git

Alternatively, you can add the user to the SSH config:

Host bitbucket
    Hostname        bitbucket.org
    User            git
    IdentityFile    /home/ivanna/.ssh/id_rsa_bitbucket
    IdentitiesOnly yes
Caseose answered 27/7, 2015 at 18:34 Comment(1)
Thank you, that was embarrassing.Perez
B
4

If you did this:

git remote add origin bitbucket:ivanna/my-repo.git

You haven't told git that it needs to connect as the something other than your username. You could do this in your .ssh/config file like this:

Host bitbucket
    User git
    Hostname        bitbucket.org
    IdentityFile    /home/ivanna/.ssh/id_rsa_bitbucket
    IdentitiesOnly yes

Or in your git remote add command line like this:

git remote add origin git@bitbucket:ivanna/my-repo.git
Beginning answered 27/7, 2015 at 18:28 Comment(2)
Well, it's git@, he's using git not hg.Palumbo
If you go and read question (w/ the output from bitbucket) you will see that either should work. Since the OP is using hg@ in the question, I stuck with that. I agree it's confusing. I'll just update the answer.Beginning
M
0

In my case, I have tried all the solution still getting permission denied error by bitbucket. Then I simply copied both public key and private key file into the .ssh folder. Finally, it's working.

Maishamaisie answered 5/2, 2023 at 23:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.