Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Permission denied (publickey)

daiyam June 7, 2017

Hi,

I'm using SourceTree v2.5.2 (111) to clone and push to Bitbucket.

When I trying the clone a project or to push, I'm getting the error:

Please make sure you have the correct access rights
and the repository exists.
Permission denied (publickey).
fatal: Could not read from remote repository.

I've tried to re-add the account, checked the ssh key, I'm still getting the error.

Any thought? Can anybody help me?

 

Thx

12 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

101 votes
Answer accepted
daiyam June 8, 2017

Hi,

I was able to fix it!

I've tried to re-authorize SourceTree in the OAuth or regenerate the ssk key with `ssh-keygen`. Both didn't worked.

I did follow the documentation configure-multiple-ssh-identities-for-osx-linux

$ ssh -Tv git@bitbucket.org
OpenSSH_6.9p1, LibreSSL 2.1.8
...
Permission denied (publickey).

$ ssh-add -l 
2048 SHA256:... /Users/user/.ssh/id_rsa (RSA)

$ ssh-add ~/.ssh/user-Bitbucket
Enter passphrase for /Users/user/.ssh/user-Bitbucket: 
Identity added: /Users/user/.ssh/user-Bitbucket (/Users/user/.ssh/user-Bitbucket)

$ ssh-add -l 
2048 SHA256:... /Users/user/.ssh/id_rsa (RSA)
2048 SHA256:... /Users/user/.ssh/user-Bitbucket (RSA)

$ ssh -Tv git@bitbucket.org
OpenSSH_6.9p1, LibreSSL 2.1.8
...
logged in as user.

Then, I was able to push my commits. It's working!

The issue might have come after the reboot of the mac. The first one since I had install SourceTree v2.5.2 (110) for a better support of OAuth...

Nilesh Jaiswal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 7, 2018

Thank You,  I had the same issue and this was helpful.  

Like # people like this
bver February 3, 2018

I had the same issue in the same scenario (after reboot I think) and this resolved it.  Thank you!

guy_silva
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 5, 2018

same issue here. The solution worked like a charm!
thanks

umar21
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 6, 2018

thnx my issue fix by above work.

vicentkarl April 14, 2018

thanks a lot!!!!

sammorala
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 21, 2018

I had the same issue, and this solution saved me a time and energy :D thank you very much.

murraycollingwood June 13, 2018

I had this problem and this solution worked.

I am on Sourcetree 2.7.3 (no recent updates).

Problem happened after an OSX update to High Sierra, osx 10.13.5 

Like richardv likes this
ralphilius
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 15, 2018

This solves my issue for ages!

patrikroh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 21, 2018

This worked like a charm, thank you!

Deleted user December 29, 2018

Thanks.

Arildo Junior
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 15, 2019

If I restart the computer I need to do this again, how to avoid this?

Like # people like this
daiyam February 15, 2019

@Arildo Junior you only need to do it once.

AndrewB
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 13, 2019

Worked for me but I only needed to do the first step, 

ssh -Tv git@bitbucket.org
Like # people like this
Vitaly Krivoshapkin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 1, 2019

Thanks man!

Iftikhar Ahmad Dar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 22, 2019

Solved my issue as well. 

Nam Lu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 23, 2019

Spot on! Thank you

krotedev
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 24, 2019

Thank you ! In my case i had to start the agent with command:


eval `ssh-agent -s`


And then run the commands listed on your answer.

Like # people like this
Deleted user January 2, 2020

If you encountered this on 

ssh-add -l
The agent has no identities.

run this 

ssh-add -K ~/.ssh/id_rsa

to add the key into ssh agent. after this, run

ssh-add -l

fyi, i'm using macOS Mojave 

Like # people like this
Sébastien Gicquel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 20, 2020

This solved my issue.

Like olegvolleto likes this
Rashad Valliyengal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 1, 2020

Wow! You save me. Thanks a lot.

meierjo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 2, 2020

Great solution!

Mayank Mathur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 30, 2020

For people like me who do not understand what do you mean by "user-Bitbucket" in 

ssh-add ~/.ssh/user-Bitbucket 

I used id_rsa again and then I was able to do all actions like fetch, pull, or push.

 

NOTE: I was able to fetch/pull/push from XCODE or terminal but for some reason source tree was unable to do so.

Thanks for the great answer above. Worked :)

Like # people like this
Chandima Gunawardhana
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 6, 2020

Thanks for info, this works for me

Annalaura Tezzon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 28, 2022

For me too, thank you so much!

wagnermelo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 22, 2022

i was having the same problem but i was able to solve it with your tip, and i just had to use ssh -Tv git@bitbucket.org

qi ren
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 10, 2022

you are great man!

to make it clear, please check all the ssh private key names in your mac then add it using the command

Brian Farias
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 24, 2022

Thanks man!! This works for me. 

Howard Lovatt March 2, 2023

This didn't work for me because it asks for a passphrase - which I don't know because the key was generated by Sourcetree - what does Sourcetree use?

3 votes
curt a
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 25, 2020

Sometimes it has to do with the ssh url in the config.

Change the url settings in the config file located under your .git folder inside your project.

i.e.

[remote "origin"]

url =git@Bitbucket.org:clicurt/appname.git

                  👇
url = https://username@Bitbucket.org/username/appname.git

This should get you connected to git using the ssh key pairs you set earlier on.

  • *Bold Italicized should be changed to your values accordingly.
Darron Smith August 31, 2020

Solved it for me in, despite everything in order above. There was one small note due to the fact that I was logging in to a "company" workspace that was not named for my account.


So where you have:

url = https://username@Bitbucket.org/username/appname.git

you might need to read it as this instead:

url = https://username@Bitbucket.org/workspace_name/appname.git

Like Arpi.Patel likes this
jcooper
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 14, 2021

This worked for me on my windows 10 machine, running tortoisegit with pageant.  Making sure to use my bitbucket username in the clone url.  

Arpi.Patel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 9, 2022

Thank you for the ans.

Your answer worked me with the help of Darron Smith's answer.

Like Darron Smith likes this
2 votes
Jan Paul Dahlke
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 6, 2021

Coming from fedora redhat OS > 33 this is actually the soultion:

 

https://www.reddit.com/r/Fedora/comments/jhxbdh/no_ssh_public_key_auth_after_upgrade_to_fedora_33/ 

Pere
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 12, 2021
1 vote
Pratyusha Simharaju
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 21, 2022

Faced the similar issue. Thanks for sharing

0 votes
danielperon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 25, 2021

For me solved running:

eval `ssh-agent -s`
ssh-add 
0 votes
Ramya Devi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 11, 2020

I also got the same error.

 

Permission denied (publickey).

fatal: Could not read from remote repository.

 

Solution: i regenerated key and added the identitiy by using the below command

ssh-add ~/.ssh/id_rsa 

then i tried giving git pull. it started working!

0 votes
Bilal Haidar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 5, 2020

Hello,

I followed all the steps above and I still get the following when I try to 'get fetch':

```

Permission denied (publickey).

fatal: Could not read from remote repository.

 

Please make sure you have the correct access rights

and the repository exists.

```

I am running on Google Cloud Compute Engine.

 

I generated a key, added it to the BitBucket, added the key to the chain etc. When I run `ssh -T git@bitbucket.org` I get the message `authenticated via a deploy key.`

 

I did try to git clone a repository on a different folder on the file system and it works fine. For this folder seems not working.

 

Thanks

0 votes
Bowofola Fadojutimi June 19, 2020

For me, i just had to delete the ssh keys in `~/.ssh` and regenerate new keys. Sourcetree was able to upload them into my github account and clone repositories again.

0 votes
Mohau R
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 10, 2019
Thank You!
0 votes
Aftab Hafeez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 28, 2019

I have to push my repository to bitbucket but whenever i try to push it or clone my local repo with server it gives me error "permission denied(publickey)" i am using git tortoise on windows 8... any idea what i am doing wrong???

Christian Schober
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 28, 2018

Thank you very much, the solution proposed in this post https://www.flynsarmy.com/2017/09/fix-permission-denied-publickey-git/ worked for me!

Like magedhamid likes this
magedhamid
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 28, 2019

Solved my issue, Thank You.

0 votes
jredmond
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 7, 2017

Which operating system are you using?

daiyam June 7, 2017

macOS v10.11.6

andrew kerr
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 7, 2017

Same occurs for me. Has happened since the upgrade to 2.5.2. Switched back to https however that keeps asking for my password constantly. Atleast I can work though.

I've also switched to GitKraken which has no issues with the same repos and ssh. Might be worth switching everything over.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events