Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atlassian / BitBucket Sourcetree SSH Public Key Denied

Tags:

git

ssh

bitbucket

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.

like image 229
Tom Granot Avatar asked Feb 25 '14 17:02

Tom Granot


People also ask

How do I add a SSH key to Sourcetree?

From Sourcetree, open the PuTTY Key Generator dialog by going to Tools > Create or Import SSH Keys. Click Load, navigate to your SSH folder, and click the private key. Make sure you're looking at All files if you don't see your private key. Enter your passphrase for the SSH key and click OK.

How do I add a public key to bitbucket?

Add the public key to your repository From Bitbucket, go to the repository and click Repository settings. Click Access keys from the left menu. Press Add key. From the Add SSH key dialog, enter a Label and paste the public key from the clipboard.


2 Answers

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.'.

like image 51
Maher Abuthraa Avatar answered Sep 29 '22 15:09

Maher Abuthraa


I needed to further modify these settings SourceTree:enter image description here

like image 21
ApceH Hypocrite Avatar answered Sep 29 '22 14:09

ApceH Hypocrite