Git权限被拒绝(publickey)在验证连接时

3
当我尝试执行以下操作时,会出现主题错误。
$ ssh -T git@github.com
Permission denied (publickey).

.ssh权限


$ ls -al
total 33
drwxr-xr-x+ 1 MyUser AGL+Group(513)    0 Feb 27 16:53 .
drwxrwxrwt+ 1 MyUser AGL+Group(513)    0 Jan 10 16:12 ..
-rw-------  1 MyUser AGL+Group(513) 1667 Feb 28 18:01 .bash_history
-rwxr-xr-x  1 MyUser AGL+Group(513) 1494 Jan  9 20:45 .bash_profile
-rwxr-xr-x  1 MyUser AGL+Group(513) 6054 Jan  9 20:45 .bashrc
-rw-r--r--  1 MyUser AGL+Group(513)   55 Feb 27 16:37 .gitconfig
-rwxr-xr-x  1 MyUser AGL+Group(513) 1919 Jan  9 20:45 .inputrc
-rwxr-xr-x  1 MyUser AGL+Group(513) 1236 Jan  9 20:45 .profile
drwx------+ 1 MyUser AGL+Group(513)    0 Feb 28 17:46 .ssh

在此之前,我执行了以下步骤:

  1. 生成了ssh密钥并存储在.ssh文件夹中
  2. 检查ssh代理

    $ ps aux |grep ssh
    7236 1 7236 7236 ? 1138370 18:26:09 /usr/bin/ssh-agent

  3. 通过设置向github账户添加公钥id_dsa.pub

MyUser@PC000009416062 ~/.ssh $ ssh -v -T git@github.com OpenSSH_7.1p2, OpenSSL 1.0.2f 28 Jan 2016 debug1: 读取配置文件 /etc/ssh_config debug1: 正在连接 github.com [192.30.252.129] 端口 22。 debug1: 已建立连接。 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_rsa 类型 -1 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_rsa-cert 类型 -1 debug1: identity file /home/MyUser/.ssh/id_dsa 类型 2 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_dsa-cert 类型 -1 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_ecdsa 类型 -1 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_ecdsa-cert 类型 -1 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_ed25519 类型 -1 debug1: key_load_public: 找不到文件或目录 debug1: identity file /home/MyUser/.ssh/id_ed25519-cert 类型 -1 debug1: 为协议版本 2.0 启用兼容模式 debug1: 本地版本字符串 SSH-2.0-OpenSSH_7.1 debug1: 远程协议版本 2.0, 远程软件版本 libssh-0.7.0 debug1: 没有匹配: libssh-0.7.0 debug1: 正在尝试使用公钥进行身份验证 debug1: SSH2_MSG_KEXINIT 发送完毕 debug1: SSH2_MSG_KEXINIT 接收到 debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none debug1: 预期 SSH2_MSG_KEX_ECDH_REPLY debug1: 服务器主机密钥: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 debug1: 已知主机 'github.com' 并与 RSA 主机密钥匹配。 debug1: 在 /home/MyUser/.ssh/known_hosts 中找到主机 github.com 的密钥 debug1: SSH2_MSG_NEWKEYS 已发送 debug1: 预期 SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS 已接收 debug1: SSH2_MSG_SERVICE_REQUEST 发送完毕 debug1: SSH2_MSG_SERVICE_ACCEPT 已接收 debug1: 可用的身份验证方法:publickey debug1: 尝试使用私钥: /home/MyUser/.ssh/id_rsa debug1: 跳过 ssh-dss 密钥 /home/MyUser/.ssh/id_dsa,因为不在 PubkeyAcceptedKeyTypes 中 debug1: 尝试使用私钥: /home/MyUser/.ssh/id_ecdsa debug1: 尝试使用私钥: /home/MyUser/.ssh/id_ed25519 debug1: 没有可用的身份验证方法

我尝试了论坛中的几个解决方案,但都没有成功。

我正在使用Cygwin进行操作。

解决方案 1

解决方案 2


请验证您的权限。您能否编辑您的帖子,以查看 .ssh 目录的权限? - Dunatotatos
你能否编辑你的帖子,附上 ssh -v -T git@github.com 的完整输出? - Dunatotatos
2个回答

4

调试1:跳过ssh-dss密钥/home/MyUser/.ssh/id_dsa,因为不在PubkeyAcceptedKeyTypes中

您生成了不被默认支持的dsa密钥。您需要添加

PubkeyAcceptedKeyTypes +ssh-dss

将以下内容添加到您的~/.ssh/config文件中,或者生成标准的RSA密钥,这些密钥可以无问题地使用。

在将该行添加到配置文件后,我收到了“Bad key types '+ssh-dsa'”错误。 - Shabar
抱歉,应该有 dss。现在已修复。 - Jakuje

2
因为你似乎正在使用 DSA 而不是默认的 RSA。你需要添加一行来在你的 SSH 客户端配置中启用它。
以下是我从这个 link 中检索到的信息:
引用: RSA 支持默认开启,但 DSA/DSS 支持需要通过以下方式启用: 在你的 SSH 客户端“config”文件中添加一行。 PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2 将配置文件命名为“config”,并放置在用户主目录/.ssh下(在 Windows 中为 /users/myname/.ssh/config)。 在当前版本中,客户端配置文件应命名为 ssh_config 而非 “config”。 SSHD 服务器端也应该在 sshd_config 文件中包含以下条目: PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2 在进行这些更改后重新启动 SSHD 服务器。

在我的情况下,由于我正在使用 Cygwin,我应该更新位于 C:\cygwin64\home\MyUser\.ssh 下的配置文件吗?因为我还有其他几个 .ssh 文件夹。此外,由于我正在连接到我的 github 帐户,我应该如何执行您解决方案中的最后一步? - Shabar
@MPH:是的,我认为它应该在C:\cygwin64\home\MyUser\.ssh中。对于第二个问题,我认为您可以跳过最后一步,因为似乎GitHub能够接受DSA密钥。(https://help.github.com/articles/what-are-github-s-ssh-key-fingerprints/) - kucing_terbang
我在提到的那一行前面添加了 # ,因为否则我会得到错误消息 /home/MyUser/.ssh/config line 49: Bad key types 'ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2'。然后从 /etc 文件夹复制 ssh_config.ssh 文件夹,并将名称更改为 config,如规定的那样。对 $ ssh -v -T git@github.com 命令的输出仍然相同。我做错了什么吗? - Shabar
你可以尝试运行 ssh -Q key 来检查客户端支持的密钥类型。 - kucing_terbang
$ ssh -Q key ssh-ed25519 ssh-ed25519-cert-v01@openssh.com ssh-rsa ssh-dss ecdsa-sha2-nistp256 ecdsa-sha2-nistp384 ecdsa-sha2-nistp521 ssh-rsa-cert-v01@openssh.com ssh-dss-cert-v01@openssh.com ecdsa-sha2-nistp256-cert-v01@openssh.com ecdsa-sha2-nistp384-cert-v01@openssh.com ecdsa-sha2-nistp521-cert-v01@openssh.com - Shabar
似乎您当前的版本不支持 ecdsa-sha2 密钥类型。您可以尝试删除该值并重试。 - kucing_terbang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接