6

1. Summarize the problem

I followed Bitbucket's instructions on setting up ssh.

I have a pub/priv key pair, and the pub key pasted into Bitbucket settings (Access Keys) for the project.

I have a build server on a GCE VM. git clone worked successfully, and git pull origin master works. I am using a passphrase.

However if I make a small change on a single file, git commit on the GCE VM, and do git push origin master, it fails with the following error message.

Enter passphrase for key '/home/proc/.ssh/id_rsa':
Unauthorized
fatal: Could not read from remote repository.

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

git remote -v shows

origin  git@bitbucket.org:<my-account>/<my-repo>.git (fetch)
origin  git@bitbucket.org:<my-account>/<my-repo>.git (push)

If git pull origin master works OK, then ssh is setup properly.

I added the following file: $HOME/.ssh/.config, with the contents below, but it did not help.

Host bitbucket.org
 IdentityFile ~/.ssh/id_rsa

my keyfile was generated with the following: ssh-keygen -t rsa -b 4096 -C "<comment>"

2. Provide background including what you've already tried

I've read every stack overflow article on Bitbucket authentication issues.

3. Show some code

git add <changed file>

git commit -m "made some updates"

git push origin master

4. Describe expected actual results including any error messages

I am trying to git push origin master to bitbucket.org.

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31
user10664542
  • 1,106
  • 1
  • 23
  • 43
  • Your private SSH key (`/home/proc/.ssh/id_rsa`) requires an extra password - see https://stackoverflow.com/a/25721662/3474146 – alex Sep 16 '19 at 13:57
  • that solution does not work. it's called a pass phrase. I have a pass phrase set on my pub/priv key pair. The problem has nothing to do with a pass phrase. The response did not help. You yourself are not able to push to Bitbucket having your public key entered into Bitbucket settings (Access Keys), for the individual project. No one can. – user10664542 Sep 17 '19 at 14:50
  • Sorry - figured *Enter passphrase for key '/home/proc/.ssh/id_rsa': Unauthorized* is probably a passphrase issue. – alex Sep 17 '19 at 15:10
  • When I enter my passphrase (correctly each time) - it gives an error: ```fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.``` It does not say incorrect passphrase, but accepts my passphrase. It's not a passphrase issue, my passphrase is 5 lowercase characters that I am entering correctly each and every time, I am able to pull with this 5 lower character passphrase, but not pull. If you have any ideas for a solution, please post. You could go try this first yourself, see the problem before responding. – user10664542 Sep 17 '19 at 15:21
  • 1
    That is a different error - I would check the local/global git configs to see what user you are pushing as, and I would check permissions on the remote Bitbucket repository to see if that user indeed has write permissions. I would also verify that the public key uploaded to Bitbucket is the same as your local public key. – alex Sep 17 '19 at 15:26
  • I have the same problem and still no solution... – Sogl Jun 24 '22 at 23:10

2 Answers2

1

Run ssh-agent /bin/sh then ssh-add ~/.ssh/id_rsa (replace id_rsa) with the name of your private key. Your push should work.

hyances
  • 13
  • 3
1

Assuming your BitBucket repository is public, anyone can pull from it without authentication. Authentication is only required when accessing a private repo or writing (pushing) to a public repo; so it's not surprising that pull and push behavior is different here.

Since you're confident your SSH passphrase is correct and your SSH keys are correctly installed on the server account, most likely it's a permission problem on the BitBucket Cloud repository itself. Check that your user has Write or Admin access in the Repository settings, AND that branch permissions/restrictions also allow you to push to the master branch you are trying to push. Both of these must be true or the push will fail with an authorization error similar to the one shown.

Dan Bonachea
  • 2,408
  • 5
  • 16
  • 31