serlingpa
serlingpa

Reputation: 12690

Git and Bitbucket: unauthorized when pushing

I have created a repository in BitBucket and have cloned it using SSH. When attempting to push my changes to BitBucket, I receive the following error:

Unauthorized

fatal: Could not read from remote repository.

I have created an SSH key using ssh-keygen and have copied the resulting public key to BitBucket. I have downloaded SourceTree to see if a bit of tooling might help, but it has the same problem.

I've been trying to fix this for hours now and don't want to waste any more time on it. Surprising, I couldn't find anyone with a similar issue or even the same error messages when searching on Google.

Please help! I am running on Mac OS X and have tried deleting GitHub credentials from Keychain Access but this hasn't solved the issue. Does anyone know what I might be doing wrong?

Update

I have used exactly the same client-side configuration with GitHub, and ran into no issues, so I'm suspecting it's some configuration on BitBucket that I'm missing.

Upvotes: 55

Views: 36980

Answers (5)

Barry D.
Barry D.

Reputation: 1731

Just had the same issue and solved it.

My issue was that I added the generated public ssh key to the repo itself through the 'settings' of that repo (tried both access-key and SSH-key).

However, that only enables read-only access (I mean git pull works).

The solution was to:

Unfortunately, now anyone having the SSH-key can mess with each and every of my repositories, hence it would be nice if we could somehow enable write access in per-repository basis (I mean for git push to work without changing our Bitbucket account).

Upvotes: 173

Jyoti Prakash
Jyoti Prakash

Reputation: 4027

If we read carefully on bit bucket while adding key at the repo security level

Use access keys to gain read-only access to this repository. Learn more about using SSH keys.

I added key to profile and it worked, Add public ssh key in

Your profile -> bitbucket settings -> SSH-Keys

Upvotes: 0

Omer Aslam
Omer Aslam

Reputation: 4874

Problem: Your public ssh key is added in REPO -> Settings -> Access keys

It only gives READ-Only Access as stated there

Use access keys to gain read-only access to this repository. Learn more about using SSH keys.

Solution: Add public ssh key in

Your profile -> bitbucket settings -> SSH-Keys

Upvotes: 99

svetlio
svetlio

Reputation: 41

I had the same issue and I have slightly different solution:

  1. Created new RSA key pair via ssh-keygen -t rsa use password for it if you want
  2. Then added the SSH Key to the ssh-agent with ssh-add ~/.ssh/<your_private_rsa_key>
  3. Add this rsa key to your bitbucket account Bitbucket -> Your Profile -> SSH Keys
  4. I logged in to the bitbucket with ssh -T git@bitbucket.org

These steps resolved the problem for me.

Upvotes: 1

sybase
sybase

Reputation: 11

You might check to see if you cloned the repository using HTTPS or SSH. Assuming you're using SSH, you could try explicitely setting up your ssh client configuration in ~/.ssh/config and define the host/private key to use:

Host <bitbucket host>
  IdentityFile <path to ssh private key>

Upvotes: 0

Related Questions