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

时间:2016-02-28 07:43:27

标签: git ssh

尝试执行以下操作时出现主题错误

$ 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. 通过设置将公钥id_dsa.pub添加到github帐户

  4. MyUser@PC000009416062 ~/.ssh $ ssh -v -T git@github.com OpenSSH_7.1p2, OpenSSL 1.0.2f 28 Jan 2016 debug1: Reading configuration data /etc/ssh_config debug1: Connecting to github.com [192.30.252.129] port 22. debug1: Connection established. debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_rsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_rsa-cert type -1 debug1: identity file /home/MyUser/.ssh/id_dsa type 2 debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /home/MyUser/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.1 debug1: Remote protocol version 2.0, remote software version libssh-0.7.0 debug1: no match: libssh-0.7.0 debug1: Authenticating to github.com:22 as 'git' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client chacha20-poly1305@openssh.com <implicit> none debug1: kex: client->server chacha20-poly1305@openssh.com <implicit> none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 debug1: Host 'github.com' is known and matches the RSA host key. debug1: Found key in /home/MyUser/.ssh/known_hosts:2 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: /home/MyUser/.ssh/id_rsa debug1: Skipping ssh-dss key /home/MyUser/.ssh/id_dsa for not in PubkeyAcceptedKeyTypes debug1: Trying private key: /home/MyUser/.ssh/id_ecdsa debug1: Trying private key: /home/MyUser/.ssh/id_ed25519 debug1: No more authentication methods to try. Permission denied (publickey).

    我在这个论坛上尝试了几个解决方案,但没有运气。 我正在使用Cygwin来执行此操作

    Solution 1

    Solution 2

2 个答案:

答案 0 :(得分:4)

  

debug1:跳过ssh-dss键/home/MyUser/.ssh/id_dsa   PubkeyAcceptedKeyTypes

您生成了dsa密钥,默认情况下不支持该密钥。你需要添加

PubkeyAcceptedKeyTypes +ssh-dss

进入~/.ssh/config,或者生成标准RSA密钥,无需解决问题。

答案 1 :(得分:2)

因为您似乎使用的是dsa而不是默认的rsa。你需要在ssh客户端配置中添加一行来启用它。

下面的

是我从此demo

中检索到的消息
  

rsa支持默认启用,但dsa / dss支持由以下内容启用:

     

在ssh客户端中添加行&#34; config&#34;文件。

     

PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2

     

- 命名配置文件&#34; config&#34;并将其放在Windows的用户主目录/ .ssh中。   /users/myname/.ssh/config

     

in the current build, the client config file is to be named ssh_config instead of "config"

     

sshd服务器端还应该在sshd_config文件中包含以下条目:   PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2   进行这些更改后重新启动sshd服务器