24

I have a strange problem with tortoise git at the moment, which I can't figure out. When trying to commit to my repository on github I get the error

ERROR: Permission to martindevans/Hermes.git denied to key2

Key2 is a key I use to access a different github repository, however the remote url is not set to use key2, as you can see here it's set to use private.ppk

enter image description here

Am I doing something obviously wrong, or is tortoise git broken?

Nb. In response to the comments. Using normal git results in:

C:\Users\Martin\Documents\Visual Studio 2010\Projects\Hermes>git push
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
2
  • Does it work correctly if you use regular Git without Tortoise? Mar 18, 2011 at 23:34
  • 1
    Great question! And now that you have an answer with a lot of votes - would you consider marking it as such? May 24, 2015 at 14:43

5 Answers 5

39

There are different private key formats. My keypair was generated with puttygen, but my Tortoise was configured to use ssh.exe (form msysgit) as ssh-client. So i changed it to plink (from Tortoise) and it worked.

  • ssh-key.exe => ssh.exe (C:\msysgit\msysgit\bin)
  • puttygen.exe => TortoisePlink.exe (C:\Program Files\TortoiseGit\bin)

Additional note: Use the correct URL! Github offers you three URL https, git and ssh.


Edit:

I adapted the settings here:

Settings - TortoiseGit >> Network >> SSH-Client
C:\Program Files\TortoiseGit\bin\TortoisePLink.exe

I have generated the key-pair with:

 C:\Program Files\TortoiseGit\bin\puttygen.exe
7
  • Also check on the "AutoLoad Putty Key" option in certain Tortoise dialogs.
    – JarodMS
    Aug 27, 2012 at 21:27
  • Where did you change it exactly?
    – acme
    Feb 25, 2013 at 14:03
  • If you want to use the OpenSSH key then what are the changes? You use the msysgit ssh and where do you put the ssh key? In the Settings->Remote it says only putty key! Feb 25, 2014 at 20:23
  • The "Additional note: Use the correct URL!" did it for me. Thanks a bunch!
    – Olaf
    Oct 4, 2014 at 6:52
  • 2
    "Additional note: Use the correct URL! Github offers you three URL https, git and ssh." Switched to HTTPS May 5, 2016 at 12:41
14

Hah! ProcMon to the rescue. This is a bug in tortoisegit / tortoiseplink. It should give preference to the key set for that remote via pageant, but instead it gives preference to the key stored in the registry by putty for that specific server. Two fixes.

2 possible fixes here

Your tortoiseplink is integrated with putty, and it's reading the private key you have saved in the putty "Session" associated with that server. At least that's what it was for me. I'm not on github though, so I don't know the viability of this solution for everybody.

I'd recommend deleting the key set manually in the putty session configuration and using pagaent for your putty sessions, as that's what tortoise git does. This also makes tortoisegit use the key set for the remote.

  1. So, you can open up putty, load whatever session you have associated with the server, go to the Connection/SSH/Auth and modify / remove the "Private key file for authentication" value. MOdification may fix this repo but then screw up another repo if you are using different keys for the same server.

  2. You can modify / delete the registry entry yourself. it's HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\$SERVERNAME$\PublicKeyFile

4
  • 1
    tortoisegit bug report : code.google.com/p/tortoisegit/issues/detail?id=1347
    – scaryman
    Nov 20, 2012 at 19:15
  • 1
    There is also the Default%20Settings as a $SERVERNAME session key that I'd missed which also contained a PublicKeyFile
    – icc97
    Dec 30, 2013 at 14:14
  • Thanks! In my case, it happens when I changed "Private key file" and Auto-login username in "Data" section under "Default Settings" on Putty. When I revert those changes TortoiseGit worked again.
    – endo64
    Dec 4, 2019 at 9:41
  • I had a private key set in my Default Settings for PuTTY under Connection -> SSH -> Auth and it broke both command-line git and TortoiseGit. PLink worked fine when I manually specified the key with the -i option, oddly enough.
    – Adam Haun
    Mar 26, 2020 at 16:13
2

I had the same problem setting up my TortoiseGit to access Bitbucket (Win10). To resolve it I had to delete the old saved host keys in the registry at HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys (not the (Default) key, tho).

1

create the key in git bash:

ssh-keygen -t rsa

Leave everything blank and don't set a password. Take the contents of the ~/.ssh/id_rsa.pub and paste it into the public key space provided by github.

Now test this by connecting to github via ssh. If that works, you will be able to use git.

hope this helps.

2
  • Creating a new key may solve the problem temporarily, but I doubt it will solve things long term. This has all been working until today where my computer is apparently deciding to use the wrong key to connect to github.
    – Martin
    Mar 19, 2011 at 4:45
  • My Git version cannot even load keys generated this way. The keys I generate with putty get loaded, the ones created with gitbash give the error: "Cannot load keyfile" when trying to push to a repo.
    – atripes
    Nov 25, 2014 at 13:59
0

I had this exact error that randomly appeared when doing a push to GitHub. I tried everything listed here to no avail. My key was still fine - I could still connect via ssh -vT git@github.com and could push/pull via Git Bash.

I even reproduced TortoiseGit working with a new key, then switching back to the old key and failing, then switching back to the new key and failing. So this seems to be a bug in TortoiseGit's integration with PuTTY, although not the one listed in @scaryman's comment above.

In the end the following worked:

  1. Upgrade to the latest PuTTY and TortoiseGit
  2. Create a new PPK using Puttygen and add the public key to GitHub
  3. Do a pull from TortoiseGit using the new PPK
  4. Open Pageant and remove the old SSH key, so the new key is the only one listed.
  5. Delete the old PPK and remove its public key from Github. This will force all repos using the old PPK to error the first time you connect to GitHub, then they automatically switch to your new PPK.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.