Windows 10下Git无法读取SSH配置导致克隆仓库失败求助
问题:Git无法识别SSH Config中的Host别名导致克隆失败
环境与配置
- 系统:Windows 10
- Git版本:2.46.0(最新版)
- SSH配置文件位于
C:\Users\<user_name>\.ssh\config,内容如下:
Host tt HostName github.com IdentityFile ~/.ssh/id_rsa_xxx IdentitiesOnly yes
问题现象
执行克隆命令:
git clone git@tt:<github_user_name>/test3.git
返回错误:
Cloning into 'test3'... ssh: Could not resolve hostname tt: Name or service not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
但直接执行ssh -T git@tt可成功通过GitHub身份验证:
Hi <github_user_name>! You've successfully authenticated, but GitHub does not provide shell access.
排查输出信息
1. git config --list结果
diff.astextplain.textconv=astextplain filter.lfs.clean=git-lfs clean -- %f filter.lfs.smudge=git-lfs smudge -- %f filter.lfs.process=git-lfs filter-process filter.lfs.required=true http.sslbackend=openssl http.sslcainfo=D:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt core.autocrlf=true core.fscache=true core.symlinks=false pull.rebase=false credential.helper=manager credential.https://dev.azure.com.usehttppath=true init.defaultbranch=master
2. 开启GIT_TRACE后的克隆输出
在PowerShell中执行$Env:GIT_TRACE=1后再运行克隆命令,输出:
09:02:58.739800 exec-cmd.c:243 trace: resolved executable dir: D:/Program Files/Git/mingw64/bin 09:02:58.763535 git.c:472 trace: built-in: git clone git@tt:<github_user_name>/test3.git Cloning into 'test3'... 09:02:58.838928 run-command.c:667 trace: run_command: unset GIT_DIR; GIT_PROTOCOL=version=2 ssh -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\''' 09:02:58.838928 run-command.c:928 trace: start_command: ssh -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\''' ssh: Could not resolve hostname tt: Name or service not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
3. 带SSH调试日志的克隆输出
执行git -c core.sshCommand="ssh -vvv" clone git@tt:<github_user_name>/test3.git,输出:
09:13:02.388635 exec-cmd.c:243 trace: resolved executable dir: D:/Program Files/Git/mingw64/bin 09:13:02.417159 git.c:472 trace: built-in: git clone git@tt:<github_user_name>/test3.git Cloning into 'test3'... 09:13:02.480940 run-command.c:667 trace: run_command: unset GIT_CONFIG_PARAMETERS GIT_DIR; GIT_PROTOCOL=version=2 'ssh -vvv' -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\''' 09:13:02.483484 run-command.c:928 trace: start_command: 'D:/Program Files/Git/usr/bin/sh.exe' -c 'ssh -vvv "$@"' 'ssh -vvv' -o SendEnv=GIT_PROTOCOL git@tt 'git-upload-pack '\''<github_user_name>/test3.git'\''' OpenSSH_9.8p1, OpenSSL 3.2.2 4 Jun 2024 debug1: Reading configuration data /etc/ssh/ssh_config debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/<user_name>/AppData/Roaming/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/<user_name>/AppData/Roaming/.ssh/known_hosts2' debug2: resolving "tt" port 22 debug3: resolve_host: lookup tt:22 ssh: Could not resolve hostname tt: Name or service not known fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
求助
如何解决Git无法识别SSH Config中Host别名的问题?
内容的提问来源于stack exchange,提问作者FrankHan
相关产品推荐
相关产品推荐

