Ivanna
Ivanna

Reputation: 1247

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

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?

Upvotes: 16

Views: 34456

Answers (3)

Meshu Deb Nath
Meshu Deb Nath

Reputation: 141

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.

Upvotes: 0

poke
poke

Reputation: 387607

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

Upvotes: 16

larsks
larsks

Reputation: 311516

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

Upvotes: 4

Related Questions