Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

git - How do I use GitHub through harsh proxies?

Given the following constraints, how can I use GitHub from Windows and Unix?

  • All access to the internet is restricted to a proxy
  • The proxy only allows connections out on port 80 and 443
  • CONNECT method is only enabled for 443
  • Proxy Authentication is required (NTLM or Basic)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See a “Using Github Through Draconian Proxies (Windows And Unix)” by Jeff Tchang (formerly available from another location), which includes instructions for both Windows and Unix platforms, summarized below.

Unix

  1. Download Git.
  2. Download and install corkscrew.
  3. Edit or create the file ~/.ssh/config and put the following:

    ProxyCommand /usr/bin/corkscrew proxy.example.com 443 %h %p ~/.ssh/myauth
    
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile "/media/truecrypt1/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile "/media/truecrypt1/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
  4. If everything is setup correctly you should be able to run ssh github.com and see

    Hi user! You’ve successfully authenticated, but GitHub does not provide shell access.
    Connection to github.com closed.

    If this doesn’t work you can run ssh ssh.github.com and get the exact same thing. If the first command didn’t work it means you are using a proxy that blocks CONNECT on port 22. Almost no proxies block CONNECT on port 443 because you need that for SSL.

Windows

  1. Download msysgit. Some settings:
    • “Run Git from the Windows Command Prompt”
    • “Use OpenSSH” (this one is very important)
    • Pick your line endings
  2. Download connect.c. This tool deserves its own post mostly because of its utter simplicity. It mirrors the open source tool corkscrew and is used for tunneling through proxies. Yes the tool’s name is really called “connect.c.” For Windows users, a pre-compiled binary is available. I put my connect.exe in C:Windowsconnect.exe.
  3. Decide whether you like to use the Windows cmd.exe to do stuff or the Cygwin style shell. Or both.
  4. Set up the Cygwin Git bash shell.

    For the Cygwin style shell start up the Git icon and edit the file ~/.ssh/config and make sure the file has no extension. Put the following in that file, and note how the paths are specified.

    ProxyCommand /c/windows/connect.exe -H [email protected]:443 %h %p
    
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile "/c/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile "/c/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
  5. Set up the Windows cmd.exe shell.

    Suppose you don’t like the Git Bash shell. You prefer the cmd.exe interpreter.

    • Go to your config file at C:Documents and Settings.sshconfig
    • Make a copy of it or make a new one. I called mine config-windows

    Put the following in the file, again paying careful attention to path separators and styles.

    ProxyCommand C:/Windows/connect.exe -H [email protected]:443 %h %p
    
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile "C:KeysGitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile "C:KeysGitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    

For full details, see the full blog post.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...