Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

permission denied (publickey) Error using git on windows 7

Tags:

git

People also ask

How do I fix Permission denied in Git?

In terminal enter this command with your ssh file name pbcopy < ~/. ssh/id_rsa. pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

How do I fix SSH permission denied Publickey?

If you want to use a password to access the SSH server, a solution for fixing the Permission denied error is to enable password login in the sshd_config file. In the file, find the PasswordAuthentication line and make sure it ends with yes . Find the ChallengeResponseAuthentication option and disable it by adding no .

How do you solve Git GitHub Permission denied Publickey fatal could not read from remote repository?

The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository. To solve this error, make sure your key is being used on your Git account. If it is not, add your key to 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


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.


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 [email protected]

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


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


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.


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