为什么git push
无法选择正确的ssh密钥?
我在计算机中使用了两个github帐户,因此我为它们配置了两个ssh密钥。下面是我的.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中失败并在另一个中成功。我在两个炮弹中测试了ssh -v git@github_zc
底部是两个shell的完整输出,为什么他们使用不同的rsa键?我可以强迫它使用正确的吗?
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
答案 0 :(得分:3)
答案是从.ssh / config
中删除默认部分#default github
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
它将找到所需的默认rsa密钥,不要在.ssh / config中配置它。