git ssh:权限被拒绝(公钥)

我试着使用 GitHub,所以我按照帮助文档进行操作。但是当我使用这个命令:ssh -vT git@github.com时,我遇到了以下错误:
jacos@Jing:~/.ssh$ ssh -vT git@github.com
OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011
debug1: Reading configuration data /home/jacos/.ssh/config
debug1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to ssh.github.com [207.97.227.248] port 443.
debug1: Connection established.
debug1: identity file /home/jacos/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/jacos/.ssh/id_rsa-cert type -1
debug1: identity file /home/jacos/.ssh/id_dsa type -1
debug1: identity file /home/jacos/.ssh/id_dsa-cert type -1
debug1: identity file /home/jacos/.ssh/id_ecdsa type -1
debug1: identity file /home/jacos/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2
debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host '[ssh.github.com]:443' is known and matches the RSA host key.
debug1: Found key in /home/jacos/.ssh/known_hosts:4
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/jacos/.ssh/id_rsa
debug1: Remote: Forced command: gerve gnijuohz 54:da:c2:c1:ca:4a:b9:4d:21:10:5b:42:3f:5a:8e:f7
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 279
Agent admitted failure to sign using the key.
debug1: Trying private key: /home/jacos/.ssh/id_dsa
debug1: Trying private key: /home/jacos/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).

代理人承认使用密钥签名?没有更多的身份验证方法可以尝试了吗?

有人能解释一下这里出了什么问题吗?

谢谢。


1这可能会有所帮助:http://serverfault.com/questions/39733/why-do-i-get-permission-denied-publickey-when-trying-to-ssh-from-local-ubunt - Ashu
3个回答

搜索谷歌关于“代理人承认使用密钥签名失败”的建议是,退出当前会话然后重新登录,或者使用ssh-add命令应该可以解决这个问题。 原因:Ubuntu使用ssh-agent程序:
 ssh-agent is a program to hold private keys used for public key authentication (RSA, DSA, ECDSA).  The idea
 is that ssh-agent is started in the beginning of an X-session or a login session, and all other windows or
 programs are started as clients to the ssh-agent program.  Through use of environment variables the agent can
 be located and automatically used for authentication when logging in to other machines using ssh(1).

如果你刚生成了一个密钥,ssh-agent并不知道它的存在,所以无法使用该密钥进行签名 - 这正是错误信息所说的。
要添加该密钥,你可以选择重新启动ssh-agent(即注销并重新登录),或者使用ssh-add重新扫描密钥。
更多信息请参阅man ssh-addman ssh-agent

它按照Sergey的解释运作,两种解决方案都很好。谢谢。 - grosshat
不,Ubuntu不使用ssh-agent。相反,它使用了SSH代理功能的另一种实现:gnome-keyring-daemon(它有自己的问题)。 - dolmen

你是否正确设置了git和ssh密钥?如果没有,请点击这里查看。

来自github的信息:

当ssh无法找到你的密钥时,也可能会出现这个问题。请确保你的密钥位于默认位置~/.ssh。如果你再次运行ssh-keygen并在三个提示处都只按回车键,它将自动放置在这里。然后,你可以将id_rsa.pub的内容添加到你的账户中。如果id_rsa.pub不起作用,请尝试id_dsa.pub。如果你只有一个rsa密钥,你可能需要使用ssh-keygen -t dsa生成一个新的dsa密钥。

P.S. 有时候URL的输入错误。URL是区分大小写的。请确保正确输入。


也可以看看这个


建议创建一个没有密码的SSH密钥是非常糟糕的安全建议。 - dolmen

使用github-keygen进行Github的SSH设置:简单、强大、安全可靠(比官方文档推荐的更安全)。
免责声明:本工具由作者撰写。