当我想设置 ssh 到我的 git 时遇到了一些问题。这是我收到的错误消息。
mbp-op-159:.ssh weiting.cheng$ ssh -vT git@github.com
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /Users/c/.ssh/id_rsa type 1
debug1: identity file /Users/c/.ssh/id_rsa-cert type -1
debug1: identity file /Users/c/.ssh/id_dsa type -1
debug1: identity file /Users/c/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/c/.ssh/known_hosts:2
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: /Users/c/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/c/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
我按照 git hub 文档上的说明进行操作,但他们没有提到我的问题。
我有私钥
debug1: identity file /Users/c/.ssh/id_rsa type 1
我还将 key 添加到我的 git hub 帐户
git成功获取到我的私钥
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/c/.ssh/id_rsa
但由于未知原因,git 继续使用我没有生成的 id_dsa。
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/c/.ssh/id_dsa
debug1: No more authentication methods to try.
然后我的权限被拒绝了。
有人有解决这个问题的建议吗?
最佳答案
您的 key 无效。我建议完全重新开始,所以请继续并删除 ~/.ssh/
文件夹中的所有内容(known_hosts
除外,您可能应该保留它)。然后运行:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
使用与您的 GitHub 帐户关联的电子邮件地址。确保 key 保存在正确的用户文件夹中。在您的情况下, key 应保存为 /Users/c/.ssh/id_rsa
。
最后,将 ~/.ssh/id_rsa.pub
的内容复制到剪贴板。转到您的 GitHub 设置,单击 SSH key 选项卡,然后添加您刚刚复制的 key 。
我相信你已经看过了,但这里有一个 more detailed walkthrough .
关于git 权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33661079/