所以,我在这件事上搞了一段时间了,但git还在闹着玩。虽然ssh现在工作得很好,但git似乎忽略了我的ssh配置,但我至少知道,当我在存储库中的sshCommand中用.git/config指定端口和键时,它可以工作。
使用配置文件,纯ssh工作得很好,但是,我使用的是Github部署键,所以我的ssh配置看起来更像这样:
host test
Hostname ssh.github.com
User git
Port 443
IdentityFile ~/.ssh/id_ed25519-test.github
IdentitiesOnly yes
host test2
Hostname ssh.github.com
User git
Port 443
IdentityFile ~/.ssh/id_ed25519-test2.github
IdentitiesOnly yes使用ssh连接仍然没有任何问题,但我想我的问题可以归结为我对主机名和主机名工作方式的误解。不太确定,ssh_config和ssh的ssh_config页面没有什么特别之处。
由于工作相关的原因,主要是我们的VPN有点不稳定,我需要使用端口443。
奇怪的是,ssh不使用github.com作为Hostname,只有当它是ssh.github.com时才能工作。我在连接到它时遇到了问题,只是在Github的文档中遇到了这样的情况,但是没有提到。用它进行了测试,从那以后,它一直运行良好。
这也在git中的遥控器中发挥作用,因为我也需要在那里追加ssh.。git remote add orgin git@github.com:user/test.git不起作用,但git remote origin2 git@ssh.github.com:user/test.git起作用。我已经测试了git是否可以通过运行git remote show <remote>并用origin或origin2替换<remote>来连接。
但是,如果不将sshCommand指定为sshCommand = ssh -p 443 -i ~/.ssh/id_ed25519-test.github,它将不会连接。
我尝试过使用以下方法进行调试:
GIT_TRACE=true \ at 11:17:27
GIT_CURL_VERBOSE=true \
GIT_SSH_COMMAND="ssh -vvv" \
GIT_TRACE_PACK_ACCESS=true \
GIT_TRACE_PACKET=true \
GIT_TRACE_PACKFILE=true \
GIT_TRACE_PERFORMANCE=true \
GIT_TRACE_SETUP=true \
GIT_TRACE_SHALLOW=true \
git remote show <remote>在使用git时,虽然我有时会删除它的GIT_SSH_COMMAND="ssh -vvv" \部分,因为它似乎覆盖了git配置文件,我想这并不奇怪。
如果我在调试ssh_command中指定了键,它至少会选择这个键,但是它仍然试图通过端口22连接到Github。这是日志:
11:20:17.116821 trace.c:375 setup: git_dir: .git
11:20:17.116867 trace.c:376 setup: git_common_dir: .git
11:20:17.116872 trace.c:377 setup: worktree: /home/user/code/test
11:20:17.116874 trace.c:378 setup: cwd: /home/user/code/test
11:20:17.116877 trace.c:379 setup: prefix: (null)
11:20:17.116879 git.c:439 trace: built-in: git remote show test
11:20:17.117075 run-command.c:663 trace: run_command: unset GIT_PREFIX; 'ssh -vvv' git@ssh.github.com 'git-upload-pack '\''github-user/test.git'\'''
OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f 31 Mar 2020
debug1: Reading configuration data /home/user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolving "ssh.github.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to ssh.github.com [140.82.121.35] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type -1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/user/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk type -1
debug1: identity file /home/user/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/user/.ssh/id_xmss type -1
debug1: identity file /home/user/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.1正如您所看到的,它完全跳过了~/.ssh/config定义。即使我在ssh命令中指定了它,它也会忽略它。这让我相信,我对host和hostname是如何工作的有一些误解,或者是有一些未被提及的行为,导致了这一点。
我还使用了ssh -vvvT <remote>来获得尽可能多的详细信息,就像前面提到的那样,普通ssh的工作非常好。当命令运行时,无论我在目录树中的位置是什么,无论我调用的是哪个host,它都运行得非常好。这就是为什么我感到困惑的原因,因为当git参与到这个过程中时,它不起作用。
这里也只安装了OpenSSH,所以我认为它不应该是一个冲突的ssh客户机。
现在,我只需为每个回购sshCommand配置添加一个ssh配置就可以了,但是,这样做实际上没有什么意义,因为它不支持git访问,而且在工作中,我的机器目前没有用于任何其他适当的ssh配置。
在过去的两周里,我一直在为这个问题绞尽脑汁,但我已经放弃了一半,并且决定至少尝试发布一个关于这个的问题,因为像这样的其他人(至少在标题上)还没有解决我的问题。希望这里的人知道出了什么问题,并告诉我如何修复它,或者至少指出一些说明我做错了什么的文档或什么东西。
发布于 2021-02-11 12:33:56
正如我所假设的,这是基于host和hostname之间相对于git远程的本质上的一个误解。虽然老实说,我并没有真正找到正确的解释,这就是他们之间的互动方式。
正如我在第一篇文章中提到的,我必须将ssh.附加到否则正常的git@github.com:user/repo中,但是没有必要在远程链接中使用github.com或ssh.github.com,因为它将在.ssh/config中定义。
如果您的.ssh/config是:
host test
Hostname ssh.github.com
User git
Port 443
IdentityFile ~/.ssh/id_ed25519-test.github
IdentitiesOnly yes您的GitHub用户名是user,您的存储库是test,您的git remote将不是git@github.com:user/test.git或git@ssh.github.com:user/test.git。它将是git@test:user/test (在本例中)。换句话说:git@<ssh config host>:<username on remote>/<remote repo name>,这是因为当它调用.ssh/config host时,它实际上读取了在host配置下定义的hostname。
最后要注意的是,在我的例子中,由于我们的网络是如何设置的,以及VPN如何与它交互,我仍然需要使用ssh.github.com作为hostname和端口443才能连接。
https://stackoverflow.com/questions/66135757
复制相似问题