【问题标题】:ssh problem caused by create another github account and add an new ssh创建另一个 github 帐户并添加新 ssh 导致的 ssh 问题
【发布时间】:2021-07-05 09:59:48
【问题描述】:

我创建了一个新的 github 帐户,因此我需要一个新的 ssh 密钥,但是在正确设置 ssh 密钥后,我无法推送我的项目。 创建新的 ssh 密钥后,我在 .ssh 目录中添加了一个配置文件,如下所示:

# one(one@gmail.com)

Host eric

HostName github.com

IdentityFile ~/.ssh/id_rsa

User eric



# two(two@ gmail.com)

Host nuist

HostName github.com

IdentityFile ~/.ssh/github_id

User nuist

然后我运行:ssh -T -v nuist,收到以下指令:

OpenSSH_8.3p1, OpenSSL 1.1.1g  21 Apr 2020
debug1: Reading configuration data /c/Users/Leonard/.ssh/config
debug1: /c/Users/Leonard/.ssh/config line 15: Applying options for nuist
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Leonard/.ssh/github_id type 0
debug1: identity file /c/Users/Leonard/.ssh/github_id-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
debug1: Remote protocol version 2.0, remote software version babeld-0913e7e1
debug1: no match: babeld-0913e7e1
debug1: Authenticating to github.com:22 as 'nuist'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: 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 /c/Users/Leonard/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/Leonard/.ssh/github_id RSA SHA256:6phvZZlW2357l+xFxmE4xSuMr1EsOFm/owFL2gikjSU explicit agent
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/Leonard/.ssh/github_id RSA SHA256:6phvZZlW2357l+xFxmE4xSuMr1EsOFm/owFL2gikjSU explicit agent
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
nuist@github.com: Permission denied (publickey)

但是,运行我:ssh -T git@github.com 之后,竟然成功了。

我猜测配置文件不起作用,但不能确定。

我看不出问题出在哪里,我也已经在我的 github 帐户中设置了 ssh。

有人可以帮忙吗?我真的很感激。

【问题讨论】:

    标签: github ssh


    【解决方案1】:

    您不需要新帐户的新密钥,只需将您的另一个 ID 添加为具有完全访问权限的协作者。

    如果以这种方式进行测试,您访问 github 的配置应为两个主机使用 User git

    运行 ssh-add -l 以检查密钥是否已加载。

    运行git remote -v 来检查 github fetch/push url,看看它们是否与 github 提供的 ssh 链接匹配。

    如果不匹配,可以用git remote set-url origin &lt;github-ssh-url&gt;设置替换成github说的链接。

    【讨论】:

    • 但是如果我将当前的公钥用于新帐户,github 会警告该密钥已在使用中,无法添加。我运行git remote -v 并获得正确的 ssh url,但在运行 git push 后,它警告说: NUIST-elite/question-bank.git 的权限拒绝 Funguy-Eric。致命:无法从远程存储库中读取。 NUIST-elite 是我的帐户,Funguy_Eric 是我的旧帐户。
    猜你喜欢
    • 2021-02-19
    • 2021-03-28
    • 1970-01-01
    • 2020-02-18
    • 2011-03-14
    • 2016-06-07
    • 1970-01-01
    相关资源
    最近更新 更多