gpt4 book ai didi

ssh - 为什么 git push 不能选择正确的 ssh key?

转载 作者:行者123 更新时间:2023-12-02 13:51:37 28 4
gpt4 key购买 nike

为什么git push不能选择正确的ssh key?

我在一台电脑上使用了两个github账号,所以我为他们配置了两个ssh key。下面是我的 .ssh/config

$ cat ~/.ssh/config
#default github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa

Host github_zc
HostName github.com
IdentityFile ~/.ssh/lifeix_beijing

但是当我执行 git push 时,它在一个 shell 中失败并在另一个 shell 中成功。我在两个 shell 中测试了 ssh -v git@github_zc
底部是两个 shell 的完整输出,为什么它们使用不同的 rsa key ?我可以强制它使用正确的吗?

PS:两个shell运行相同的命令ssh -v git@github_zc

输出的相同部分是:

Reading configuration data /home/lifeix/.ssh/config
...
debug1: identity file /home/lifeix/.ssh/lifeix_beijing type 1
debug1: identity file /home/lifeix/.ssh/lifeix_beijing-cert type -1
debug1: identity file /home/lifeix/.ssh/id_rsa type 1
debug1: identity file /home/lifeix/.ssh/id_rsa-cert type -1

不同的是:失败了

debug1: Offering RSA public key: /home/lifeix/.ssh/id_rsa
...
Hi qinglangee! You've successfully authenticated, but GitHub does not provide shell access.

成功了

debug1: Offering RSA public key: /home/lifeix/.ssh/lifeix_beijing
...
Hi iamzc! You've successfully authenticated, but GitHub does not provide shell access.

失败 shell 的输出:

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/lifeix/.ssh/config
debug1: /home/lifeix/.ssh/config line 7: Applying options for github_zc
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Hostname has changed; re-reading configuration
debug1: Reading configuration data /home/lifeix/.ssh/config
debug1: /home/lifeix/.ssh/config line 3: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.252.129] port 22.
debug1: Connection established.
debug1: identity file /home/lifeix/.ssh/lifeix_beijing type 1
debug1: identity file /home/lifeix/.ssh/lifeix_beijing-cert type -1
debug1: identity file /home/lifeix/.ssh/id_rsa type 1
debug1: identity file /home/lifeix/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.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_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_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 /home/lifeix/.ssh/known_hosts:43
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/lifeix/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.252.129]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_IDENTIFICATION = zh_CN.UTF-8
debug1: Sending env LC_TIME = zh_CN.UTF-8
debug1: Sending env LC_NUMERIC = zh_CN.UTF-8
debug1: Sending env LC_PAPER = zh_CN.UTF-8
debug1: Sending env LC_ADDRESS = zh_CN.UTF-8
debug1: Sending env LC_MEASUREMENT = zh_CN.UTF-8
debug1: Sending env LC_MONETARY = zh_CN.UTF-8
debug1: Sending env LC_NAME = zh_CN.UTF-8
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_TELEPHONE = zh_CN.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi qinglangee! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed.
Transferred: sent 4240, received 1800 bytes, in 0.5 seconds
Bytes per second: sent 9312.4, received 3953.4
debug1: Exit status 1

成功shell的输出:

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/lifeix/.ssh/config
debug1: /home/lifeix/.ssh/config line 7: Applying options for github_zc
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Hostname has changed; re-reading configuration
debug1: Reading configuration data /home/lifeix/.ssh/config
debug1: /home/lifeix/.ssh/config line 3: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.252.129] port 22.
debug1: Connection established.
debug1: identity file /home/lifeix/.ssh/lifeix_beijing type 1
debug1: identity file /home/lifeix/.ssh/lifeix_beijing-cert type -1
debug1: identity file /home/lifeix/.ssh/id_rsa type 1
debug1: identity file /home/lifeix/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.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_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_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 /home/lifeix/.ssh/known_hosts:43
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/lifeix/.ssh/lifeix_beijing
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.252.129]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LC_IDENTIFICATION = zh_CN.UTF-8
debug1: Sending env LC_TIME = zh_CN.UTF-8
debug1: Sending env LC_NUMERIC = zh_CN.UTF-8
debug1: Sending env LC_PAPER = zh_CN.UTF-8
debug1: Sending env LC_ADDRESS = zh_CN.UTF-8
debug1: Sending env LC_MEASUREMENT = zh_CN.UTF-8
debug1: Sending env LC_MONETARY = zh_CN.UTF-8
debug1: Sending env LC_NAME = zh_CN.UTF-8
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_TELEPHONE = zh_CN.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi iamzc! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 1 clearing O_NONBLOCK
Connection to github.com closed.
Transferred: sent 4240, received 1784 bytes, in 0.5 seconds
Bytes per second: sent 9371.6, received 3943.2
debug1: Exit status 1

最佳答案

答案是从 .ssh/config 中删除默认部分

#default github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa

它会找到所需的默认 rsa key ,不要在 .ssh/config 中配置它。

关于ssh - 为什么 git push 不能选择正确的 ssh key?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28779977/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com