'SSH clone/push to Bitbucket Forbidden

When I clone through ssh, I have the error like this:

Forbidden fatal: Could not read from remote repository.

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

I have followed up a few tutorials. The pub key is added to my account in personal settings => security => SSH keys

There is a trouble shooting page. I loaded the key by using

ssh-add

If I run

ssh -T [email protected]  

I got

authenticated via ssh key.

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

This response doesn't fit to any cases, it doesn't show pubkey errors, etc. The closest case, which is the correct response is:

authenticated via ssh key.
"conq: logged in as username."
You can use git to connect to Bitbucket. Shell access is disabled

The "" part is missing in my case.

That is why I can't find a solution through other posts.

My port 22 is not blocked, I can ssh to my server or other places well. I am doing this at home, there isn't any extra firewall. I can ssh clone on Github using keys.

Update:

I removed the key in Bitbucket and tried to add the same key. It shows a duplication error:

Someone has already added that SSH key.

After removed the key, I tried the ssh command again, it shows

authenticated via ssh key.

Theoretically, there exists no duplicated keys. If I added this key, no one else can add it again. When I remove it, this key shouldn't exist in their database anymore, so that the ssh command should gives invalid pubkey error and there shouldn't be a duplication error when I tried to add it agin.

I really feel there is a bug on my account on Bitbucket, but I really believe this can happen.



Solution 1:[1]

My port 22 is not blocked, I can ssh to my server or other places well.

At work, I can also ssh to other servers within the enterprise LAN (Local Area Network).

But I would most certainly not be able to SSH to any internet-facing servers.

Assuming this is not the case here, it can depend on your OS, SSH version and SSH key.

Try with a new key: ssh-keygen -P "" -t rsa -f ~/.ssh/testbb, and register testbb.pub to your account.

Add a ~/.ssh/config file with:

Host bb
  Hostname bitbucket.org
  User git
  IdentityFile ~/.ssh/testbb

And test it with ssh -Tv bb.

Solution 2:[2]

If you get following response via ssh -T bitbucket.org, you're good to go:

authenticated via ssh key.

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

On my machine I'm getting the same answer. I'm not sure where you got the information that this reply should contain your user name, but it's not true.

Just try it out with, for example:

git clone [email protected]:atlassian/ssh-run.git

Solution 3:[3]

If you have multiple private keys in your $HOME/.ssh to access remote repositories, your git command might be using the wrong one (even if you added correct key to ssh-agent and removed others and ssh -T [email protected] is successfull). Try explicitly specifying which SSH key to use with environment variable:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example -F /dev/null" git clone example

If it works, learn How to tell git which private key to use and save the setting permanently.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC
Solution 2 Andrejs Cainikovs
Solution 3