设置SSH后,Github权限被拒绝(publickey)

时间:2016-08-17 15:22:27

标签: git github ssh terminal gitlab

我试图将我的Gitlab存储库转移到Github,但是当我尝试将其推送时(根据各种指南),我总是收到错误:Permission denied (publickey).

我已经通过Github教程在本地添加SSH密钥然后多次添加到我的Github帐户,但它仍然无法正常工作。以下是一些各种命令的输出。

(我已经完成了keygen命令)

$ eval "$(ssh-agent -s)"
Agent pid 84168

$ ssh-add -l -E md5
The agent has no identities.

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /Users/isaiahmayerchak/.ssh/id_rsa: <my-passphrase>
Identity added: /Users/isaiahmayerchak/.ssh/id_rsa (/Users/isaiahmayerchak/.ssh/id_rsa)

$ ssh-add -l -E md5
4096 MD5:0c:44:3d:28:de:17:71:e5:29:18:bf:a1:8c:8j:mf:3c /Users/isaiahmayerchak/.ssh/id_rsa (RSA)

$ ssh -vT git@github.com
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /Users/isaiahmayerchak/.ssh/config
debug1: /Users/isaiahmayerchak/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: identity file /Users/isaiahmayerchak/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/isaiahmayerchak/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
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 /Users/isaiahmayerchak/.ssh/known_hosts:9
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/isaiahmayerchak/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/isaiahmayerchak/.ssh/id_dsa
debug1: Trying private key: /Users/isaiahmayerchak/.ssh/id_ecdsa
debug1: Trying private key: /Users/isaiahmayerchak/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

在Github上,我添加的SSH密钥完全匹配我的本地密钥,但在Github上它说它还没有被使用。

我已经为我的用户名和电子邮件设置了github配置。我也试过ssh -i ~/.ssh/id_rsa -vT git@github.com ,但这对我没有任何帮助。我真的需要在接下来的两天内将此存储库转移到工作中。我见过的故障排除文章都没有帮助;他们都认为ssh -vT git@github.com会在他们的步骤之后起作用,但对我来说并不适用。有人可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

手动将本地计算机ssh密钥添加到github配置文件中。

cat ~/.ssh/id_rsa.pub

复制上述命令的输出并将其粘贴到&#34; Github - &gt;设置 - &gt; SSH和GPG密钥 - &gt;新的SSH密钥&#34;。

答案 1 :(得分:0)

我在Mint Linux 19上遇到了类似的问题,尽管细节与您的并不完全相同,但我想分享自己的经验,以造福他人:

运行ssh-keygen后,通过html将我的密钥添加到我的github帐户,并通过以下方式成功连接到github:

 ssh -vT git@github.com

当我尝试使用以下语法通过ssh克隆存储库时,我遇到了“权限被拒绝”错误:

git clone ssh://USERNAME@github.com/USERNAME/REPOSITORY

截至2020年7月3日,我在有关此问题的评论中尝试了所有解决方案,但没有任何帮助。然后我去了github,发现this

哪个告诉我:

始终使用“ git”用户

所有连接(包括远程URL的连接)都必须作为 “ git”用户。如果您尝试使用GitHub用户名进行连接,它将 失败:

$ ssh -T GITHUB-USERNAME@github.com

权限被拒绝(公钥)。

如果连接失败,并且您将远程URL与 GitHub用户名,您可以更改远程URL以使用“ git”用户。

按照此说明进行操作后,我通过SSH正常连接。

对我有用的语法是:

git clone ssh://git@github.com/USERNAME/REPOSITORY
相关问题