Reputation: 1850
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:
.ppk
(PuTTY Private Key) to Pageant using my passphraseC:/Project
.git init
to initialize the repository.git push -u origin --all
in order to push the repo from my computer to BitBucket.Permission denied (publickey).
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.
Upvotes: 40
Views: 41058
Reputation: 1
you’ll need to reset the permissions to default:
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub
If you are getting another error:
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/geek/.ssh/known_hosts).
This means that the permissions on that file are set incorrectly, and can be fixed with the next:
sudo chmod 644 ~/.ssh/known_hosts
And you should to adjust the directory permissions:
sudo chmod 755 ~/.ssh
Maybe you still got an error access denied on mac, try this one:
ssh-add --apple-use-keychain ~/.ssh/id_rsa
Upvotes: 0
Reputation: 610
This is an old question, but every time there is a MacOS update, I came across this issue. Catalina was no exception.
First, you should check your config file to confirm if your old keys still there... it should:
~ ls -al ~/.ssh
Then you have to add again your key(s) by the name listed above:
~ ssh-add -K ~/.ssh/[key-name]
Upvotes: 5
Reputation: 43
This happened to me after updating my Sourcetree on my Mac.
What worked for me was just simply removing everything in the ~/.ssh/
folder except the .config
and the known_hosts
folders. Then simply go to sourcetree under preferences, remove your github account, re-add the profile again after deleting all the .ssh
public and private keys and sourcetree should re-add the keys locally and to GitHub
Upvotes: 4
Reputation: 17813
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.'.
Upvotes: 87
Reputation: 111
I know this is resolved, but to add to the accepted answer, you don't actually need Git Bash in order for this to work. As Cupcake said, it is true that PuTTY puts out .ppk
files for private keys, which won't work outside the usual PuTTY/Pageant context.
This is because the terminal expects by default to find a file named id_rsa
in ~/.ssh
and PuTTY doesn't generate that by default. Git Bash's ssh-keygen
does though, which is why Tom Granot's solution works.
You CAN, though, through the PuTTY key generator, export the same exact file through the Conversions/Export OpenSSH Key...
option in the menu. Just be sure to name it id_rsa
and have it sit next to your id_rsa.pub
file, and everything should work fine.
Upvotes: 10
Reputation: 1850
Well - I've found the solution after much trial and error.
Apparently, using PUTTY's keygen and storing the new public key in my .ssh
folder doesn't work.
However, using ssh-keygen
IN GIT BASH and then trying to login using the new generated key pair, works just fine.
Out of curiosity though more than anything - I would love to know why this is the case.
Upvotes: 10