在 Windows 7 上的代理后面的 git 中的 SSH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5103083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:06:06  来源:igfitidea点击:

SSH in git behind proxy on windows 7

windowsproxyssh

提问by Soni Anand

I am testing SSH connection for checking RSA key in git. I am working over proxy server. I am using window 7 and have installed msysGit-fullinstall-1.7.3.1-preview20101002. Now in msys.exe window i have set proxy by command 'git config --global http.proxy http://host:port' After that i have tried command 'ssh [email protected]' . This gives me error like 'ssh: github.com: no address associated with name'

我正在测试 SSH 连接以检查 git 中的 RSA 密钥。我正在处理代理服务器。我正在使用窗口 7 并安装了 msysGit-fullinstall-1.7.3.1-preview20101002。现在在 msys.exe 窗口中,我通过命令 'git config --global http.proxy http://host:port'设置了代理,之后我尝试了命令 'ssh [email protected]'。这给了我类似“ssh:github.com:没有与名称关联的地址”的错误

What should i do?

我该怎么办?

回答by wimh

Setting http.proxywill not work for ssh. You need to proxy your ssh connection. See thisdescription. To summarize:

设置http.proxy不适用于 ssh。您需要代理您的 ssh 连接。请参阅说明。总结一下:

Start git-cmd.batand create ~/.ssh/config(notepad %home%\.ssh\config.)

启动git-cmd.bat和创建~/.ssh/config( notepad %home%\.ssh\config.)

ProxyCommand /bin/connect.exe -H proxy.server.name:3128 %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile "C:\users\username\.ssh\id_rsa"
  TCPKeepAlive yes
  IdentitiesOnly yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\users\username\.ssh\id_rsa"
  TCPKeepAlive yes
  IdentitiesOnly yes

(set the correct proxy hostname:port, and the path to id_rsa. When you use git-bash, use slashes in the path to id_rsa)
(My version of msysgitincludes connect.exe, so I do not need to download and compile connect.c). A precompiled exe is also available here.

(设置正确的代理主机名:端口,以及id_rsa的路径。当你使用git-bash时,在id_rsa的路径中使用斜杠)
(我的msysgit版本包括connect.exe,所以我不需要下载和编译connect.c) . 预编译的 exe 也可在此处获得

Now ssh github.comshould work

现在ssh github.com应该工作

Note that if you want to connect via a socks5 proxy, then change -Hto -S.

请注意,如果您想通过socks5 代理连接,则更-H改为-S.

ProxyCommand connect -S proxy.server.name:1080 %h %p

If you use a Linux file system, the file permission of ~/.ssh/configmust be 600, but on a standard NTFS windows partition, these kind of permissions do not exist.

如果你使用的是Linux文件系统,文件权限~/.ssh/config必须是600,但是在标准的NTFS windows分区上,这种权限是不存在的。

If your proxy requires NTLM authentication, you can use cntlm, see also this answer.

如果您的代理需要 NTLM 身份验证,您可以使用cntlm,另请参阅此答案

回答by Ian Vaughan

Does your proxy require a password? Then it might be that.

您的代理是否需要密码?那么可能就是这样。

export http_proxy="http://<domain>\<username>:<password>@<server>:<port>"

export http_proxy="http://<domain>\<username>:<password>@<server>:<port>"

See : How do I pull from a Git repository through an HTTP proxy?(duplicate!)

请参阅:如何通过 HTTP 代理从 Git 存储库中提取?(复制!)