I've got Git for Windows (configured for MinTTY and PuTTY\plink.exe
) and PuTTY installed, and am trying to get it to work with a BitBucket repository. I've got my SSH key loaded, in Pageant and on the website, and yet whenever I attempt to do anything that requires pulling/pushing:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I run the suggested ssh -v hg@bitbucket.org
it uses id_rsa
but none of my other keys in ~/.ssh
. Trying to use ssh-add ~/.ssh/bitbucket_rsa
results in:
Could not open a connection to your authentication agent.
I've read about configuring PuTTY to allow forwarding, but that's usually where the advice ends, so I just set this option for the default session and saved it there.
I've run ps
to check which applications were running, and ssh-agent
was not among them. Running eval 'ssh-agent'
starts the daemon but it makes no difference.
To access ssh keys loaded in Pegeant from git bash, that comes with Git-on-Windows, you can use this program. The installation process is described on the linked page.
You don't need putty to work with BitBucket in ssh: the openssh (
C:\prgs\git\PortableGit-2.7.0-64-bit\usr\bin\ssh.exe
) packaged in git-for-windows works just fine.Make sure that, in your current shell session, you have HOME set to
%USERPROFILE%
(aPortableGit-2.7.0-64-bit\git-cmd.exe
is enough to open a regular CMD properly configured)Create in
%USERPROFILE%\.ssh
a file namedconfig
(as in step 3 of the Atlassian doc):(You can also use "
/C/path/to/bitbucket_rsa
")That allows to use an ssh url like
bitbucket.org:user/repo
.Test it with
ssh -Tv bitbucket.org
(after adding your public key to your BitBucket account, of course)Note:
ssh-agent
is only needed if your private key is passphrase-protected.Update 2018, 2 years later: "Say Farewell to Putty as Microsoft adds an OpenSSH Client to Windows 10".
It is really time to ditch putty aside: no need for a different (ppk) key format and proprietary solution, now that openssh is officially distributed as a Windows feature (in beta for now, Q1 2018).
You are mixing things up.
PuTTY and Pageant are not compatible with openSSH tools and can't communicate together. PuTTY can't read keys from your openssh agent and openssh can't read the keys from Pageant. The key format is also different. That is bad thing in this world, but there is no solution on the horizon.
Also "agent forwarding" is something different than "using agent".
If you set up Git with plink (make sure you really did), check if your Pageant is running and if in your stored profile in PuTTY under Connection->SSH->Auth, the option "Attempt authentication using Pageant" is checked.
If it will not resolve your problems, post some debug log from putty.
what worked for me with git bash for windows 7: convert .pkk file to open-ssh format:
add generated key to IdentityFile .ssh/config at git bash e.g:
This is what ended up working for me.
Btw, I do have bash on Windows as well, but I don't think that matters.
I had SourceTree installed and pointed at its folder with
plink.exe
,puttygen.exe
, &pageant.exe
. You could also download and install these separately as well.Configure Windows Environment Variable
Environment
into your Windows 10 search bar. Otherwise, open up System Properties / Advanced System Settings and find your Environment Variables.plink.exe
file (you may also havepageant.exe
andputtygen.exe
in the same folder).C:\Program Files (x86)\Atlassian\SourceTree\tools\putty\plink.exe
plink.exe
and put it somewhere that's not going to change.plink.exe
.Profit
Make sure to restart your terminals so that they get the updated environment variables. For me, I was running bash for my integrated terminal within VSCode, so I had to restart VSCode. It would have surely been acceptable to close the integrated terminal and open a new one, but I also wanted the built in git functionality in VSCode to work as well.
Note
Given that I have SourceTree installed I was able to use its interface to clone down out of BitBucket and push through its interface, but trying through terminals was not working because they were using a different credential set.
Another interesting thing to point out is that if you navigate into your project's git configuration located at:
./.git/config
, you could swap out your remote from using ssh to https. You can grab the following values from your Overview on your BitBucket repository.git@bitbucket.org:USERNAME/REPO_NAME.git
https://USERNAME@bitbucket.org/USERNAME/REPO_NAME.git
I noticed while using https on Windows 10 it then will use the Windows Credential Manager (I tried adding my credentials to it while trying to figure this out myself, but I was still using SSH so it didn't matter) When you go to interact with the remote repository it will prompt you for your credentials and store them for later use in Windows Credential Manager :)
Hopefully one of these methods will work out for you. The HTTPS method will skip the whole SSH key generation and pushing it up into BitBucket, but feels more secure and portable for me.
Mac OS
You may need to add your key to the keychain especially if you're using VSCode and have a passphrase on your key (Currently VSCode will not allow you to type in a passphrase).
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent