34

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 git@github.com' . This gives me error like 'ssh: github.com: no address associated with name'

What should i do?

pgpb.padilla
  • 2,318
  • 2
  • 20
  • 44
Soni Anand
  • 341
  • 1
  • 3
  • 4

2 Answers2

66

Setting http.proxy will not work for ssh. You need to proxy your ssh connection. See this description. To summarize:

Start git-cmd.bat and create ~/.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 msysgit includes connect.exe, so I do not need to download and compile connect.c). A precompiled exe is also available here.

Now ssh github.com should work

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

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

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

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

wimh
  • 15,072
  • 6
  • 47
  • 98
  • It works fine, as long as `~/.ssh/config` has the right permission. But the way, it's a pity that the answer is correct but not accepted yet. – stanleyxu2005 Jul 15 '15 at 03:44
  • 2
    On my system connect.exe was installed in a different location. To get it to work I had to set ProxyCommand "/c/Program Files/Git/mingw64/bin/connect.exe" -S proxy.server.name:1234 %h %p (note I am using SOCKS5 not http so I changed the H to S) – gnash117 Mar 31 '16 at 17:44
  • That **connect.exe** link has been dead. Does anybody know an alternative link? – kujiy Jul 03 '17 at 06:33
  • 4
    Thanks @wimh. I also found it in my windows machine at **C:\Program Files\Git\mingw64\bin\connect.exe** that Git for Windows 64bit is installed. – kujiy Jul 03 '17 at 09:25
  • This answer with **connect.exe** works fine but it seems not to support the password for socks5 proxy. My socks must need both ID and Password in addition to ssh ID & Password. I'd like to use like `ProxyCommand connect -S ID:PASSWORD@proxy.server.name:1080 %h %p` but it gets an error. `ProxyCommand connect -S ID@proxy.server.name:1080 %h %p` works well but typing a password every time is annoying. – kujiy Jul 03 '17 at 09:29
  • 1
    I cannot comment here, so I create this answer which should be comment for wimh For git bash on Window, please change /bin/connect.exe to connect.exe Anyway, thank for great info. – Karoshi Jul 18 '18 at 00:50
  • 1
    In GitBash, I used the `connect.exe` in the link but got error `syntax error near unexpected token 'newline' Connection closed by remote host`. After I changed to `"/c/Program Files/Git/mingw64/bin/connect.exe"`, it works well. – Evan Hu Jul 30 '18 at 04:28
  • 4
    With latest official Windows Git version, I had to use `ProxyCommand connect.exe -H proxy.server.name:3128 %h %p` (`connect.exe` is bundled in git's `mingw64\bin` directory which seems to be added in the path when running a `git` command) – Anthony O. Dec 18 '18 at 10:52
-2

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

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

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

Community
  • 1
  • 1
Ian Vaughan
  • 20,211
  • 13
  • 59
  • 79