Atlassian / BitBucket Sourcetree SSH Public Key Denied

Tom Granot picture Tom Granot · Feb 25, 2014 · Viewed 37.5k times · Source

I'm working on a project in a private repository on https://www.bitbucket.com.

I'm coding it locally, then staging, commiting and pushing the update via BitBucket's / Atlassian's Windows Git client, Sourcetree.

After that, I'm pulling the files from a remote shared server, which requires SSH authentication.

I've tried the following in order to connect the git repo with the BitBucket account:

  1. Launched the embedded Sourcetree SSH agent (Pageant)
  2. Added my .ppk (PuTTY Private Key) to Pageant using my passphrase
  3. Opened the SourceTree Terminal in the location of my project, let's call it C:/Project.
  4. Used git init to initialize the repository.
  5. Used git push -u origin --all in order to push the repo from my computer to BitBucket.
  6. Got this error: Permission denied (publickey).
  7. Tried to see if I can get some more verbose output by doing ssh -Tv [email protected] - Still, Permission denied.

I'm trying to figure out what exactly went wrong - did Sourcetee find my SSH key at all? Is the key not loaded in some specific place, causing this behavior?

Note: I have loaded the public key in my profile on BitBucket.

Answer

Maher Abuthraa picture Maher Abuthraa · Feb 10, 2017

To whom may have the same issue on Mac with new Sierra. Solution would be to add private key to SSH agent via:

ssh-add -K ~/.ssh/id_rsa

It looks like that identity[id_rsa] doesn't persist by SSH agent.

Note this is not a permanent solution .. You would need to do that each time you clone a new repository.At least then no need to provide private key for each push to remote.

-------- Update 28.Sep.2017 --------

Permanent solution ( On Sierra):

Steps:

1- Be sure that you have a running ssh-agent in background before doing anything.

To check if ssh-agent is running by:

pgrep 'ssh-agent'

That command returns PID (ProcessID) of that process if it's running. If you see a value.. Go to Step#2. if not, so you need to run that agent in background by:

eval "$(ssh-agent -s)"

2- Edit ~/.ssh/config (Create if it doesn't exist as su ):

Host *
 AddKeysToAgent yes
 UseKeychain yes
 IdentityFile ~/.ssh/id_rsa

3- Then add that key agent ( that would be once ):

ssh-add -K ~/.ssh/id_rsa

That's it.

Actually Step#2 is the crucial one. I just want to provide a complete guide.

I hope that may help you.'.