【发布时间】:2021-10-12 05:57:13
【问题描述】:
虽然我的 Linux 机器可以使用其主机名访问 NAS 上的托管存储库,但我的 Windows 机器无法从命令行/Visual Studio Code 访问它。在我的调试尝试中,我找到了一种至少 TortoiseGit 可以访问存储库的方法:我必须添加一个环境变量GIT_SSH_COMMAND=ssh -vvv(除了已经存在的GIT_SSH=C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe)。
当我通过 cmd 为通过 url = ssh://gituser@my-devices-hostname/volume1/git/reponame.git 在 Git 配置中访问的存储库发出 git pull 时,我得到以下输出:
OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "my-devices-hostname" port 22
debug2: ssh_connect_direct
debug1: Connecting to my-devices-hostname [192.168.0.50] port 22.
getaddrinfo: atch: Name or service not known
ssh: connect to host my-devices-hostname port 22: failure
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
当我用静态 IP 替换主机名时,我得到了同样的错误:
OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 192.168.0.50 is address
debug2: ssh_connect_direct
debug1: Connecting to 192.168.0.50 [192.168.0.50] port 22.
getaddrinfo: atch: Name or service not known
ssh: connect to host 192.168.0.50 port 22: failure
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
当用 TortoiseGit 做同样的事情时,一切正常,我明白了:
OpenSSH_8.1p1, OpenSSL 1.1.1d 10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "my-devices-hostname" port 22
debug2: ssh_connect_direct
debug1: Connecting to my-devices-hostname [192.168.0.50] port 22.
debug1: Connection established.
...
我最近设置了一个新的 DSL 路由器 (Fritz!Box 7590),这可能与此有关。由于我猜测问题可能与 IPv6 有关,因此我在 Synology NAS 上禁用了 IPv6,但没有任何变化。
更新: fedrik 让我执行手动 ssh。结果如下:
ssh gituser@my-devices-hostname
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to my-devices-hostname closed.
令人惊讶的是:
ssh gituser@196.168.0.50
ssh: connect to host 196.168.0.50 port 22: Connection timed out
我更新了我的 Git- 和 Tortoise 安装,现在我得到了
ssh gituser@192.168.0.50
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.168.0.50 closed.
基于主机名的 ssh 保持不变。
受 VonC 回答的启发,我检查了我的系统上是否安装了多个 ssh 实例。我发现了以下内容:
C:\Windows\System32\OpenSSH\ssh.exe
C:\Program Files\Git\usr\bin\ssh.exe
所以我检查了(在为 Windows 更新了 Tortoise 和 Git 之后),使用了哪一个。首先,我离开了 GIT_SSH_COMMAND=ssh -vvv:
git pull
OpenSSH_8.4p1, OpenSSL 1.1.1h 22 Sep 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/user/.ssh/known_hosts2'
debug2: resolving "my-devices-hostname" port 22
debug2: ssh_connect_direct
debug1: Connecting to my-devices-hostname [192.168.0.50] port 22.
getaddrinfo: atch: Name or service not known
ssh: connect to host my-devices-hostname port 22: failure
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
"C:\Program Files\Git\usr\bin\ssh.exe" -vvv gituser@192.168.0.50
OpenSSH_8.4p1, OpenSSL 1.1.1h 22 Sep 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 192.168.0.50 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/bjoer/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/bjoer/.ssh/known_hosts2'
debug2: ssh_connect_direct
debug1: Connecting to 192.168.0.50 [192.168.0.50] port 22.
debug1: Connection established.
在我更改了环境变量后:GIT_SSH_COMMAND=C:/Windows/System32/OpenSSH/ssh.exe -vvv 我得到了这个:
git pull
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug3: Failed to open file:C:/Users/user/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolving "my-devices-hostname" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to my-devices-hostname [192.168.0.50] port 22.
getaddrinfo: atch: Der angegebene Host ist unbekannt.
ssh: connect to host my-devices-hostname port 22: failure
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
C:\Windows\System32\OpenSSH\ssh.exe -vvv gituser@192.168.0.50
OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug3: Failed to open file:C:/Users/user/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.168.0.50 is address
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.0.50 [192.168.0.50] port 22.
debug1: Connection established.
当我取消设置 GIT_SSH 和 GIT_SSH_COMMAND 环境变量时,我得到了这个:
git pull
getaddrinfo: atch: Name or service not known
ssh: connect to host my-devices-hostname port 22: failure
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
所以,我可以通过 SSH 连接到 Git 服务器,但是当 Git 可执行文件本身出现问题时,它会失败。
当我在同一台机器上启动 WSL 时,我可以毫无问题地执行 git pull。
关于如何解决这个问题有什么建议吗?
【问题讨论】:
-
这是某种形式的网络问题。也可能是由旧的 git 版本加上新版本的支持库引起的——或者相反。由于您使用的是 Tortoise,这也可能是原因的一部分。你能对主人做一个简单的
ssh吗? -
感谢您的提示,弗雷德里克!为了提高可读性,我已将我之前的答案合并到问题中。