Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 759
Ivanna Avatar asked Jul 27 '15 18:07

Ivanna


People also ask

Why is my SSH key not working?

Make sure the authorized_keys file and the private key itself have the correct permissions and ownership. Check that key-based authentication is allowed by the server. Make sure the private key is readable by the SSH client. If you're using PuTTY, make sure your SSH keys are properly configured for the session.

How do I generate my SSH public key in Bitbucket?

From Bitbucket, go to the repository and click Repository settings. Click Access keys from the left menu. Press Add key. From the Add SSH key dialog, enter a Label and paste the public key from the clipboard.


1 Answers

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
like image 167
poke Avatar answered Sep 27 '22 22:09

poke