permission denied (publickey) Error using git on windows 7

后端 未结 15 1936
暖寄归人
暖寄归人 2021-01-29 22:35

When I want to push to github with this command

git push origin master

I got this

Permission denied (publickey).
fatal: The rem         


        
相关标签:
15条回答
  • 2021-01-29 22:58

    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!

    0 讨论(0)
  • 2021-01-29 22:59

    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

    0 讨论(0)
  • 2021-01-29 22:59

    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/ ??

    0 讨论(0)
  • 2021-01-29 22:59

    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

    0 讨论(0)
  • 2021-01-29 22:59

    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

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题