【问题标题】:Github permission denied (publickey) after I set up SSH我设置 SSH 后 Github 权限被拒绝(公钥)
【发布时间】:2020-07-04 01:01:57
【问题描述】:

我正在尝试将我的 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 ,但这对我也没有任何好处。我真的需要在接下来的 2 天内转移此存储库以进行工作。我看过的故障排除文章都没有帮助;他们都认为ssh -vT git@github.com 会在他们的步骤之后工作,但它不适合我。有人可以帮我吗?

【问题讨论】:

  • 您可以尝试手动添加吗?
  • 您是否添加了密钥或指纹?
  • 我不确定指纹是什么,但是我已经手动将密钥添加到Github(我添加密钥的唯一方法是手动)

标签: git github ssh terminal gitlab


【解决方案1】:

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

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

 ssh -vT git@github.com

然后,当我尝试使用以下语法通过 ssh 克隆存储库时遇到了 Permission Denied 错误:

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

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

这告诉我:

始终使用“git”用户

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

$ ssh -T GITHUB-USERNAME@github.com

权限被拒绝(公钥)。

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

按照此说明,我通过 SSH 连接没有错误。

对我有用的语法是:

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

【讨论】:

    【解决方案2】:

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

    cat ~/.ssh/id_rsa.pub
    

    复制上述命令的输出并粘贴到“Github -> Settings -> SSH and GPG Key -> New SSH Key”。

    【讨论】:

    • 这是我最初将密钥放入Github的做法;它已经存在了
    • flysaiah : 你能删除现有的密钥并再次尝试添加它吗?
    • 我尝试了 3 次不同的时间,包括生成新密钥。我比较了两者,它们是相同的
    • 你是如何生成一个新的?。
    • ssh-keygen -t rsa -b 4096 -C "my-email-address@example.com"
    猜你喜欢
    • 1970-01-01
    • 2018-11-06
    • 2011-11-25
    • 2019-11-24
    • 2014-11-08
    • 2019-03-11
    • 1970-01-01
    • 2012-01-18
    • 2012-04-25
    相关资源
    最近更新 更多