SSH - Permission denied (cannot authenticate git@g

2019-02-26 20:07发布

问题:

I'm on windows XP. I'm facing weired problem as when I try to connect to git@github.com using bash ssh -v git@github.com i'm able to connect successfully but when i am trying to connect via cmd on same machine I'm getting message permission denied.

On debugging I found that in case of bash, ssh is checking id_rsa key but in case of cmd SSH is just checking github_rsa. Not even trying to check id_rsa. Below are the logs.

OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Applying options for github.com
debug1: Connecting to github.com [204.232.175.90] port 22.
debug1: Connection established.
debug1: identity file /c/Documents and Settings/username/.ssh/github_rsa type 1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debia n-6+squeeze1+github12
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1+github12 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
Warning: Permanently added 'github.com,204.232.175.90' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Documents and Settings/username/.ssh/github_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

Please suggest what could be the possible case. Some suggests to check the file permissions on my key. Both keys have same file permissions i.e. -rw-r--r--

Below is the updated code after making changes mentioned by @naomi

OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Applying options for github.com
debug1: Connecting to github.com [204.232.175.90] port 22.
debug1: Connection established.
debug1: identity file /c/Documents and Settings/username/.ssh/github_rsa type 1
debug1: identity file /c/Documents and Settings/username/.ssh/id_rsa type 1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze1+github12
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1+github12 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
Warning: Permanently added 'github.com,204.232.175.90' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Documents and Settings/username/.ssh/github_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: Offering public key: /c/Documents and Settings/username/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

回答1:

Look in the file

/etc/ssh/ssh_config

It probably has an entry in it for github telling it where the id file is. Change this to the one you want it to use

If that doesn't work you can always copy id_rsa to github_rsa ...



回答2:

Both keys have same file permissions i.e. -rw-r--r--

You actually let people, logged on your system, read your id_rsa private key, which is not good. Actually, your id_rsa key should have 600 (-rw-------) permission, and it's done by issuing chmod 600 id_rsa command. Also, check .ssh folder permissions too and set them to 700