permission denied (publickey) Error using git on windows 7

Git

Git Problem Overview


When I want to push to github with this command

git push origin master

I got this

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

So, what's wrong?

Git Solutions


Solution 1 - Git

EUREKA!

Apparently, you can use plink as the main ssh client and just load your keys in pageant (if you're like me, you already do):

You can do that by setting the GIT_SSH env variable to plink.exe path like so: > set GIT_SSH=C:\Program Files\PuTTY\plink.exe

or, you can use plink from TortoiseGit: > set GIT_SSH=c:\Program Files\TortoiseGit\bin\TortoisePLink.exe

Credit: Original solution taken from this blog post

Solution 2 - Git

I was able to resolve this issue as follows:

When you do:

ssh-keygen -t rsa

it prompts you to (optionally) enter a filename for saving the generated keys. Specifying a filename wasted my whole day! Next day I let it use the default filename and the problem(s) disappeared! Imagine!!

Platform was Win7 and msysgit.

Solution 3 - Git

Here is a step-by-step guide that I used to get this to work.

Platform: Windows 7

Install msysgit from http://msysgit.github.io/

During installation, accept all of the default options, except when the 'Select Components' option appears. When this appears, select 'Git Bash Here' option. Although this isn't necessary, it adds a nice context menu when working in Windows Explorer that I found to be very helpful.

enter image description here

Once msysgit is installed Git Bash will also be installed. Open Git Bash in one of 2 ways:

  • Click the Windows Start key and start typing Git Bash
  • Or, right click somewhere (e.g. your Desktop) and select Git Bash Here. This option is only available if 'Git Bash Here' context menu was installed.

In Git Bash's command window, enter this:

$ ssh-keygen -t rsa

When asked to enter a file name, just accept the default. Choose a strong passphrase when prompted, and your public key should now be saved. Your screen should look like this:

enter image description here

Go open the public key file in Notepad. The file should reside here:

C:\Users\{username}\.ssh\id_rsa.pub

Copy all of the content in the file to your clipboard, then go to GitHub's SSH settings page:

https://github.com/settings/ssh

Choose 'Add SSH key', enter a useful 'Title' and paste the content into the 'Key' textarea.

To simplify your life, you can use the SSH agent to save your passphrase so that you don't need to remember it. To do so, type this into Git Bash:

$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/id_rsa

You'll be prompted to enter your passsphrase. If everything succeeds, your identity will have been added. Note: this passphrase will be forgotten as soon as you close your shell. I'm not sure how to make this persist across sessions, but maybe someone can help?

To test that everything works, enter this into Git Bash:

$ ssh -T git@github.com

You should see a 'success' meesage.

Sources:

https://help.github.com/articles/generating-ssh-keys/

https://help.github.com/articles/working-with-ssh-key-passphrases/

explanation on why eval `ssh-agent -s` should be used instead of just ssh-agent -s

https://stackoverflow.com/a/17848593/188740

Solution 4 - Git

Have you generated an SSH key for yourself and added it to your Github account? They have a guide for this here.

Solution 5 - Git

Using Windows 8 to setup your ssh and Github

  1. If it says "Permission denied (publickey)" you will have to put in a passphrase for your key. Do not be tempted to just press enter...this was what worked for me...it took me five hours to realize that pressing enter made OpenSSH feel that your key was too public so that is why it is denying you from going to the next step.

  2. If it says "The authenticity of host 'github.com (203.232.175.90)' can't be established." Then you will have to go through the process shown here: [Google] (https://help.github.com/articles/error-permission-denied-publickey.)

Go to the part that says "Verify the public key is attached to your GitHub account". You want to start with the part that says account. (I am assuming you already have an account.

Also, you want to be in C:\RailsInstaller\Git.ssh and when I did 'dir' I noticed that I had '.', '..', 'known_hosts'. I had to get a new key by doing the following (I found this on the Github site): > "ssh-keygen -t rsa -C "[email protected]" > # Creates a new ssh key, using the provided email as a label > # Generating public/private rsa key pair. < # Enter file in which to save the key(/c/Users/you/.ssh/id_rsa): [Press enter]"

And pay attention to the file where the key will be saved. Do not just press enter.. my one showed "(//.ssh/id_rsa)" I had to type "/.ssh/id_rsa" to make sure it was in the right directory.

And you should be able to type ssh in the command line. If you cannot do that you will have to add it to your path.

Solution 6 - Git

I solved a similar problem by adding a System Environment Variable. The key was that I am pointing to the git.exe inside the cmd folder

name: GIT
value: C:\Program Files (x86)\Git\cmd\git.exe

Solution 7 - Git

there could be something wrong with your heroku keys. try:

heroku keys:add

similar question here: https://stackoverflow.com/questions/10873032/heroku-git-fatal-the-remote-end-hung-up-unexpectedly

Solution 8 - Git

If you have already generated the key, and it has a default name, the problem might be in the absent environment variable.

On Windows 7 right click "My computer" and go to properties. There click on advanced properties and click the button Environment Variables. There add a user environment variable

Name: HOME 
Value: %USERPROFILE%

Solution 9 - Git

The problem may be related to the order in which the ssh.exe are in the PATH environmental variable.

In my case there was a ssh.exe in both the C:\Program Files(x86)\git and also in my C:\cwgwin directory. When I was in my Git Bash everything worked fine (it was using the ssh in the git directory) but when I was in my Command Prompt it was using the ssh in my cygwin directory.

When I tried to access github it was not able to find the .ssh folder with my private key because the key was not attached to the ssh the command prompt was using (ie the C:\cygwin one) and that is why I was getting the Permission Denied error.

What I did was rename (or delete) the git.exe and ssh.exe in my C:\cygwin directory and make sure that C:\Program Files(x86)\git appears before the C:\cwgwin in the PATH order.

Solution 10 - Git

Here is a solution to a very specific problem that has the same error signature. This was the mistake I made and it is very easy to make. Basically, instead of doing this

  git remote add origin git@github.com:myusername/myrepo.git

I did this (note typo)

  git remote add origin get@github.com:myusername/myrepo.git

http://www.celticwolf.com/blog/2011/02/08/git-permission-denied-publickey/

Solution 11 - Git

Here is the default output for Windows 7.

c:\test\app>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Could not create directory '//.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
open //.ssh/id_rsa failed: No such host or network path.
Saving the key failed: //.ssh/id_rsa.

Instead of command prompt git is to be used as per http://help.github.com/win-set-up-git/ ??

Solution 12 - Git

I had a similar problem:

I created "redssh" and "redssh.pub" in some directory using git bash. Permission denied...

however, "id_rsa.pub" and "id_rsa" had appeared in: C:/Users/myName/.ssh/

copy id_rsa.pub contents to github

Solution 13 - Git

I'm a total newb with git and was following some installation instruction on a website and was getting the permission denied (publickey) error.

I followed the instructions to generate the RSA key pairs (ssh-keygen -t rsa). This worked fine but I was still getting the error. What I did not realize was that you have to actually go the the GIT website (github.com), register and enter that key on their website.

I hope this helps out another poor newb out there.

Cheers!

Solution 14 - Git

I had similar Prob in win 8.

Very Simple mistake I did: I have already created public key in git hub account so that y keys was not getting match.

Solution:

  • delete ssh folder and key from github account and do it again the process
  1. ssh-keygen -t rsa -C "your mail address"

  2. ssh -T [email protected]

Solution 15 - Git

This is a very common problem and all beginners face this issue. Here is how to resolve the problem.

  1. Open gitbash

  2. Update your email address in below command.

    ssh-keygen -t ed25519 -C "[email protected]"

  3. Then copy your ssh key to clipboard with below command.

    clip < ~/.ssh/id_ed25519.pub

  4. Open your git account from the browser. goto settings -> ssh and gpg keys -> click on "New ssh key" add name and key in the text box then press save and git will ask you to enter your account password please enter that and your ssh key will be configured.

That's it it should resolve your problem if not then please do let me know. I'll help you troubleshoot the issue.

Peace.

Solution 16 - Git

I discovered that my problem was that whatever version of ssh-keygen that I used created the files with the wrong filenames... The files initially created where %USER_HOME%.ssh\ida_rsa and ida_rsa.pub, but git expected them to be id_rsa and id_rsa.pub.

I solved the problem by running git bash, THEN running ssh-keygen

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser257805View Question on Stackoverflow
Solution 1 - GittutuDajujuView Answer on Stackoverflow
Solution 2 - GitG ShahView Answer on Stackoverflow
Solution 3 - GitJohnny OshikaView Answer on Stackoverflow
Solution 4 - GitVeetiView Answer on Stackoverflow
Solution 5 - GitTashaView Answer on Stackoverflow
Solution 6 - GitmynkowView Answer on Stackoverflow
Solution 7 - GitAlexander TaylorView Answer on Stackoverflow
Solution 8 - GitVladimir BeletskiyView Answer on Stackoverflow
Solution 9 - GitLeo MooreView Answer on Stackoverflow
Solution 10 - GitAlan BerezinView Answer on Stackoverflow
Solution 11 - Gituhbl92View Answer on Stackoverflow
Solution 12 - GitxxjjnnView Answer on Stackoverflow
Solution 13 - Gituser3220701View Answer on Stackoverflow
Solution 14 - GitAjay GangardeView Answer on Stackoverflow
Solution 15 - GitMitesh vaghelaView Answer on Stackoverflow
Solution 16 - GitKbCbView Answer on Stackoverflow