Permission denied (PublicKey) and its workarounds due to a mismatch in SSH configuration files

Source: Internet
Author: User
Tags ssh config ssh config file git shell

If the reader wants to reprint, please indicate the source and the author's name, thank you.
Address 01:http://space.itpub.net/25851087
Address 02:http://www.cnblogs.com/zjrodger/
Author Name: Zjrodger

"problem occurrence environment and related parameters"

(1) Os:win7 32Bit.

(2) Git:github for Windows 2.0.

: https://windows.github.com/

(3) Command shell:git Shell.

"Problem recurrence description"After installing GitHub for Windows 2.0 on the Win7 local platform, generate the key locally, pass the key to GitHub, and perform network connectivity testing. ① using the command " ssh-keygen-t rsa-c "[email protected]"Generate SSH Key ( Id_rsaAnd id_rsa.pub), place the local " id_rsa.pubThe contents of the file are uploaded to the personal SSH keys management item on GitHub, resulting in a new SSH keys. After ②, make a local connection test with the remote Server (GitHub Web site), and the commands and results are as follows:
f:\workspaces\github_workspace> ssh-t [email protected]
warning:permanently added ' github.com,192.30.252.131 ' (RSA) to the list of know
N hosts.
Permission denied (publickey).
In Windows PowerShell, enter the ssh-t [email protected]", the result appears" Permission Denied (publickey)


"Cause of the problem"On GitHub for Windows 2.0 defaultIn the installation configuration,  Configuration file for SSH Ssh_configIn the " Identityfile "Not consistent with the actual situation. (1) The Identifyfile value of the original by defaultOn GitHub for Windows 2.0 ( The default installation scenario), the configuration file for SSH Ssh_configIn the " Identityfile(its value is the full path name of the key) "The content of this information is " ~/.ssh/github_rsa, as shown in the following command:
Host github.com stricthostkeychecking No userknownhostsfile=/dev/null identityfile=~/.ssh/github_ RSA
  (2) The actual situationand actualOn, by command " ssh-keygen-t rsa-c "[email protected]The generated New SSH KeyOf Full path nameFor: " ~/.ssh/id_rsa "And " ~/.ssh/id_rsa.pub ".   Note :~/.ssh/ Github_rsa Not equal to ~/.ssh/id_rsa   (3) Conclusion①git The default installation scenarioThe value of the "Identityfile" entry in the Ssh_config configuration file: identityfile= ~/.ssh/github_rsa② the value of the actual identityfile: identityfile= ~/.ssh/id_rsaAs mentioned above, Github for Windows 2.0 The default installation scenario, the configuration file for SSH Ssh_configIn the " Identityfile "The value of the item does not match the actual newly created key full path name, resulting in the local SSH tool not finding the correct key, and thus unable to match the upload to GitHub key, the result appears " Permission denied (publickey)"Such a mistake.
(4) Supplement SSH config file ssh_config on its own local path: C:\Users\Administrator\AppData\Local\GitHub\PortableGit_ 6d98349f44ba975cf6c762a720f8259a267ea445\etc\ssh Storage path of key file: C:\Users\Administrator\.ssh Ssh_config original file (in the wrong version):
Host *
Stricthostkeychecking No
Userknownhostsfile=/dev/null


Host github.com
Stricthostkeychecking No
Userknownhostsfile=/dev/null
Identityfile=~/.ssh/github_rsa
After you reload GitHub for Windows 2.0 new Discoveries (important)
To ensure correctness, I uninstalled and re-installed the native GitHub for Window 2.0 and found the SSH configuration file Ssh_configIn the " Identityfile "is still " ~/.ssh/github_rsa”。 And after the re-installed key file storage path (C:\USERS\ADMINISTRATOR\.SSH), there are four key files, respectively, is Github_rsaAnd github_rsa.pubId_rsaAnd id_rsa.pub, so that users do not have to create their own new key files, only using the " github_rsa.pubContent is uploaded to the GitHub Web site's personal ssh management. After that, the network connectivity test was conducted locally and remote, and it was found to be connected. In this way, the author does not recommend to modify the SSH configuration file manually, considering the hidden trouble of modifying the original configuration information of the software. Ssh_configIn the " Identityfile "Field of this method.

"Workaround" method One:After generating the new key file, if the newly generated key file is named " Id_rsa, change the value of the "Identityfile" entry in the Ssh_config configuration file to " ~/.ssh/id_rsa(pro-test effective) Method Two:Change the name of the newly generated key file to " Github_rsa, which is the same as the value of the "Identityfile" entry in the Ssh_config configuration file.
Method Three:     Reload GitHub for Window 2.0 without creating a new key file, but using GitHub's own " github_rsa.pubFile anyway, regardless of method one, put two or method three, be sure to keep the name of the newly generated key file with the "Identityfile" field in "Ssh_config" the value of the same.

Permission denied (PublicKey) and its workarounds due to a mismatch in SSH configuration files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.