Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 607
K.C. Avatar asked Dec 18 '25 23:12

K.C.


2 Answers

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.

like image 199
VonC Avatar answered Dec 20 '25 15:12

VonC


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.

like image 34
o.pash Avatar answered Dec 20 '25 16:12

o.pash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!