0

if my key is named id_rsa.pub and I put it into bitbucket ssh setting. It is working out of box. When I ssk-keygen name like id_rsa_else.pub, then insert to ssh key setting. It is saying

repository access denied.
fatal: Could not read from remote repository.

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

Update 1

the following gives me the error above:

Host andatech_bitbucket_my_username
  HostName bitbucket.org
  User andatech_my_username
  IdentityFile ~/.ssh/andatech_my_username_bitbucket
kenpeter
  • 7,404
  • 14
  • 64
  • 95
  • git or mercurial? – Flurin Jun 02 '17 at 12:33
  • I am using git at the moment. – kenpeter Jun 02 '17 at 12:34
  • Some possible solutions are here: https://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command-with-or-without-ruby – Flurin Jun 02 '17 at 12:39
  • username for bitbucket should be "git" and not andatech_.... – Flurin Jun 02 '17 at 13:01
  • Also: did you add the andatech_my_username_bitbucket key to bitbucket. Because in the beginning of your question you're talking about id_rsa_else as the name of the key. – Flurin Jun 02 '17 at 13:02
  • I change user to git. andatech_my_username_bitbucket is inside ssh key setting in my uesr profilke in bitbucket. Same error repository access denied. – kenpeter Jun 02 '17 at 13:30
  • Bitbucket does permit the username instead of "git" or "hg" when the key is associated with a specific account. – Jim Redmond Jun 03 '17 at 00:04

3 Answers3

1

Add the following to your ssh config file. It's usually the file: ~/.ssh/config

Host bitbucket.org
  IdentityFile ~/.ssh/id_rsa_else

id_rsa_else is the name of your key. This tells ssh which private key to use when talking to bitbucket.org.

Flurin
  • 681
  • 5
  • 14
1
Host bitbucket.org 
  HostName bitbucket.org
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/andatech_xxx_bitbucket

Based on this: https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html

kenpeter
  • 7,404
  • 14
  • 64
  • 95
0

Are the remotes on your repos listed as "andatech_bitbucket_my_username" or as "bitbucket.org"? (You can run git remote get-url origin to see the URL for the remote named "origin".) If the first part of the URL isn't "andatech_bitbucket_my_username", then SSH won't refer to that stanza in your config, and as a result it won't use the key you want.

If that's the problem, then you can fix it in one of two ways: either update repos to use "andatech_bitbucket_my_username" instead of "git@bitbucket.org" or whatever you have listed there (git remote set-url origin andatech_bitbucket_my_username), or update your ~/.ssh/config to have Host bitbucket.org in place of Host andatech_bitbucket_my_username.

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18