git debug gerrit无法review代码

git debug gerrit无法review代码

系统环境

hackintosh
version 10.15.4(19E287)

ssh -V
OpenSSH_8.1p1, LibreSSL 2.7.3

问题描述

无法用git通过ssh方式从公司仓库pull代码, 向gerrit提交代码, 但是可以在github.com上拉取代码

解决方式(for those who have no patience)

  1. 安装下openssh(但实际是已经安装的了)
brew install openssh
  1. 将key交换算法写到配置文件
cat << EOF >> ~/.ssh/config
KexAlgorithms diffie-hellman-group1-sha1,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
EOF

杂谈

执行完解决方式后,发现ssh的版本发现变化了(新开一个terminal)
ssh -V
OpenSSH_8.2p1, OpenSSL 1.1.1f 31 Mar 2020
虽然上面的方式解决了我的问题,但是是什么导致的却还是没有解决,哈哈哈

排查过程

使用git ssh debug

# Example on Linux
GIT_SSH_COMMAND="ssh -vvv" git clone ssh://git@<bitbucket URL>:<bitbucket port>/<project key>/<repository slug>.git

公司结果

OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/steveguan/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to review.sh.99cloud.net port 29418.

github结果

OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/steveguan/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/steveguan/.ssh/id_rsa type 0
debug1: identity file /Users/steveguan/.ssh/id_rsa-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_dsa type -1
debug1: identity file /Users/steveguan/.ssh/id_dsa-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_ecdsa type -1
debug1: identity file /Users/steveguan/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_ed25519 type -1
debug1: identity file /Users/steveguan/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_xmss type -1
debug1: identity file /Users/steveguan/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version babeld-e598ce58
debug1: no match: babeld-e598ce58
debug3: fd 4 is O_NONBLOCK
debug1: Authenticating to github.com:22 as 'git'
debug3: hostkeys_foreach: reading file "/Users/steveguan/.ssh/known_hosts"
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
......

从结果看,连接公司gerrit,好像没有发出请求,下面使用tcpdump石锤下。

尝试下抓包,分别使用curl和 ssh -vvv -p 29418 review.sh.99cloud.net, curl可以在本地抓到包,但是ssh不行。

sudo tcpdump -i en1  dst 172.16.30.17 and port 29418 -vvv
tcpdump: listening on en1, link-type EN10MB (Ethernet), capture size 262144 bytes



172.16.30.1713:43:52.712289 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 64)
    192.168.199.124.54487 > review.sh.99cloud.net.29418: Flags [S], cksum 0x274c (correct), seq 1082723547, win 65535, options [mss 1460,nop,wscale 6,nop,nop,TS val 767949437 ecr 0,sackOK,eol], length 0
13:43:52.722075 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.199.124.54487 > review.sh.99cloud.net.29418: Flags [.], cksum 0x9967 (correct), seq 1082723548, ack 2122821370, win 2058, options [nop,nop,TS val 767949446 ecr 1426342667], length 0
13:43:52.722141 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 134)
    192.168.199.124.54487 > review.sh.99cloud.net.29418: Flags [P.], cksum 0xba32 (correct), seq 0:82, ack 1, win 2058, options [nop,nop,TS val 767949446 ecr 1426342667], length 82
13:43:52.731683 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.199.124.54487 > review.sh.99cloud.net.29418: Flags [.], cksum 0x98d0 (correct), seq 82, ack 51, win 2058, options [nop,nop,TS val 767949455 ecr 1426342677], length 0
13:43:52.747070 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.199.124.54487 > review.sh.99cloud.net.29418: Flags [.], cksum 0x988d (correct), seq 82, ack 97, win 2057, options [nop,nop,TS val 767949469 ecr 1426342685], length 0
13:43:52.747158 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 52)
    192.168.199.124.54487 > review.sh.99cloud.net.29418: Flags [F.], cksum 0x988c (correct), seq 82, ack 97, win 2057, options [nop,nop,TS val 767949469 ecr 1426342685], length 0

尝试了一把 brew install openssh
然后再试就可以连接了

 ssh -vvv -p 29418 review.sh.99cloud.net
OpenSSH_8.2p1, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /usr/local/etc/ssh/ssh_config
debug2: resolving "review.sh.99cloud.net" port 29418
debug2: ssh_connect_direct
debug1: Connecting to review.sh.99cloud.net [172.16.30.17] port 29418.
debug1: Connection established.
debug1: identity file /Users/steveguan/.ssh/id_rsa type 0
debug1: identity file /Users/steveguan/.ssh/id_rsa-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_dsa type -1
debug1: identity file /Users/steveguan/.ssh/id_dsa-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_ecdsa type -1
debug1: identity file /Users/steveguan/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/steveguan/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_ed25519 type -1
debug1: identity file /Users/steveguan/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/steveguan/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/steveguan/.ssh/id_xmss type -1
debug1: identity file /Users/steveguan/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2
debug1: Remote protocol version 2.0, remote software version GerritCodeReview_2.11 (SSHD-CORE-0.14.0)
debug1: no match: GerritCodeReview_2.11 (SSHD-CORE-0.14.0)
debug2: fd 5 setting O_NONBLOCK
debug1: Authenticating to review.sh.99cloud.net:29418 as 'steveguan'
debug3: put_host_port: [review.sh.99cloud.net]:29418
debug3: hostkeys_foreach: reading file "/Users/steveguan/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /Users/steveguan/.ssh/known_hosts:49
debug3: load_hostkeys: loaded 1 keys from [review.sh.99cloud.net]:29418
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: [email protected],[email protected],[email protected],rsa-sha2-512,rsa-sha2-256,ssh-rsa,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],ssh-ed25519,[email protected]
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,ssh-dss
debug2: ciphers ctos: aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes256-ctr,arcfour256,arcfour128
debug2: ciphers stoc: aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes256-ctr,arcfour256,arcfour128
debug2: MACs ctos: hmac-md5,hmac-sha1,hmac-md5-96,hmac-sha1-96
debug2: MACs stoc: hmac-md5,hmac-sha1,hmac-md5-96,hmac-sha1-96
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: (no match)
Unable to negotiate with 172.16.30.17 port 29418: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

然后增加下面内容到~/.ssh/config文件,便可以解决 kex: algorithm: (no match)

KexAlgorithms diffie-hellman-group1-sha1,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1

你可能感兴趣的:(----------Mac,OSX,git,ssh,macos)