2

我在 Windows XP 上。我遇到了奇怪的问题,因为当我尝试使用 bash ssh -v git@github.com连接到 git@github.com 时 ,我能够成功连接,但是当我尝试在同一台机器上通过 cmd 连接时,我是获取消息权限被拒绝。

在调试时,我发现在 bash 的情况下,ssh 正在检查 id_rsa 密钥,但在 cmd 的情况下,SSH 只是在检查 github_rsa。甚至没有尝试检查 id_rsa。以下是日志。

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).

请提出可能的情况。有人建议检查我的密钥的文件权限。两个密钥具有相同的文件权限,即-rw-r--r--

以下是@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).
4

2 回答 2

0

两个密钥具有相同的文件权限,即 -rw-r--r--

您实际上让登录您的系统的人读取您的 id_rsa 私钥,这不好。实际上,您的 id_rsa 密钥应该具有 600 (-rw-------) 权限,这是通过发出chmod 600 id_rsa命令来完成的。此外,还要检查 .ssh 文件夹权限并将其设置为 700

于 2013-12-04T13:45:07.477 回答
0

在文件中查看

/etc/ssh/ssh_config

它可能有一个 github 条目,告诉它 id 文件在哪里。将此更改为您希望它使用的那个

如果这不起作用,您可以随时将 id_rsa 复制到 github_rsa ...

于 2013-08-07T13:22:37.390 回答