Skip to content

Instantly share code, notes, and snippets.

@oldthreefeng
Last active October 11, 2020 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldthreefeng/a2e2846a0c3a647f54c2a83bc1a50669 to your computer and use it in GitHub Desktop.
Save oldthreefeng/a2e2846a0c3a647f54c2a83bc1a50669 to your computer and use it in GitHub Desktop.
ssh proxy github.com
## use ssh proxy github.com on linux/ubuntu/mac os/ windows .
# A highest way to get resource from github.com
A local host (git client),B is jumpserver(can fastest get resource from Github),C is Github host 。
by using ssh forward ,A could tunnel B to get C,so we can fastest get resource from Github。
@oldthreefeng
Copy link
Author

oldthreefeng commented Sep 26, 2020

+-----+             +-----+             +-----+
|     |             |     |             |     |
|  A  +-----------> |  B  +-----------> |  C  |
|     |             |     |             |     |
+-----+             +-----+             +-----+

Use ssh to proxy

on windows

tips: delete the comments with # in config

git config

cat ~/.ssh/config
Host fenghong.tech          # your proxy hosts , liki B
    HostName fenghong.tech
    IdentityFile ~/.ssh/id_rsa
    User root   # some one can login your server 
    Port 22		# your proxy hosts ports. default is 22
Host github.com	     # your destination hosts, like c
    HostName github.com
    IdentityFile ~/.ssh/id_rsa
    User git
    Port 22
    ProxyCommand ssh.exe -q -W %h:%p fenghong.tech

On mac / Linux / Ubuntu /

git config

tips: delete the comments with # in config

cat ~/.ssh/config
Host fenghong.tech          # your proxy hosts , liki B
    HostName fenghong.tech
    IdentityFile ~/.ssh/id_rsa
    User root   # some one can login your server 
    Port 22		# your proxy hosts ports. default is 22
Host github.com	     # your destination hosts, like c
    HostName github.com
    IdentityFile ~/.ssh/id_rsa
    User git
    Port 22
    ProxyCommand ssh -q -W %h:%p fenghong.tech

In addtion . some ssh client do not support -W . you can use this command instead. by the way , window has no nc. so, this is a linux way~

    ProxyCommand  ssh proxyuser@proxy.machine nc %h %p 2> /dev/null

@oldthreefeng
Copy link
Author

Use socks5 to proxy .

On mac / ubuntu / centos

$ cat ~/.ssh/config 
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand nc -v -X 5 -x 127.0.0.1:1080 %h %p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment