Recently, I can’t access Bitbucket frequently, and the speed of dragging code from Github is slow. Everyone knows the reason.
Therefore, the best way is to set up a proxy for Git. I hope to specify some warehouses to use the proxy method. I don’t know how to set it up?
In the local environment, I set up an ssh agent and go to 127.0.0.1:7070 through SOCKS. If the local ssh agent is turned on, Is there another way?
滿天的星座2017-05-02 09:35:57
Three protocols currently supported by Git git://
、ssh://
和 http://
,其代理配置各不相同:core.gitproxy
用于 git://
协议,http.proxy
用于 http://
协议,ssh://
协议的代理需要配置 ssh 的 ProxyCommand
Parameters.
Create the /path/to/socks5proxywrapper
file and use the https://bitbucket.org/gotoh/connect tool to convert the proxy. Each distribution is generally packaged as proxy-connect or connect-proxy.
#!/bin/sh
connect -S 127.0.0.1:7070 "$@"
Configure git
[core]
gitproxy = /path/to/socks5proxywrapper
or
export GIT_PROXY_COMMAND="/path/to/socks5proxywrapper"
Create /path/to/soks5proxyssh
file
#!/bin/sh
ssh -o ProxyCommand="/path/to/socks5proxywrapper %h %p" "$@"
Configure git to use this wrapper
export GIT_SSH="/path/to/socks5proxyssh“
Of course it can also be configured directly ~/.ssh/config
的 ProxyCommand
[http]
#这里是因为 Git 使用 libcurl 提供 http 支持
proxy = socks5://127.0.0.1:7070
/path/to/socks5proxywrapper
file is changed to #!/bin/sh
connect -H 192.168.1.100:8080 "$@"
[http]
proxy = http://192.168.1.100:8080
gitproxy parameter provides the core.gitproxy part of * for *
结构,具体看 man git-config
.
高洛峰2017-05-02 09:35:57
You can set http.proxy or core.gitproxy for this repository
git config http.proxy http://user:pwd@server.com:port
git config core.gitproxy '"proxy-command" for example.com'
http://www.kernel.org/pub/software/sc...
过去多啦不再A梦2017-05-02 09:35:57
You can use yanyaoer's method to set up a proxy for git.
As for the ssh+pac+socks agent you mentioned, it does not conflict with the git agent mentioned by yanyaoer.
The socks proxy is a circuit-level underlying proxy, while the proxy set in git config is application-level.
For example, your pac is set up for github.com to use socks 127.0.0.1:7070; and the git config is set up for github.com to use proxy.server.com as a proxy.
Then at this time, when you perform git operations, all network requests will go to proxy.server.com when they reach the socks layer. Naturally, they will not be affected and will go out directly.
習慣沉默2017-05-02 09:35:57
tsocks - http://tsocks.sourceforge.net/
$ tsocks git clone git@github.com:xxx/xxx.git
淡淡烟草味2017-05-02 09:35:57
If you clone from bitbucket and use the ssh protocol, you can use all ssh proxy methods
For example, if it is an http proxy or socks proxy, you can use http://bent.latency.net/bent/git/goto... This small program is used as the hostProxyCommand
If there is a relay server you mentioned, you can use nc
on the remote host to do itnc
做ProxyCommand
http://www.undeadly.org/cgi?action=ar...
As for the differentiated traffic you mentioned, you can make different settings in ~/.ssh/config
. For example, the configuration I used before
Host bitbucket.org ProxyCommand ~/.ssh/connect -H 192.168.1.106:3128 %h 22
In this way, git clone ssh://git@bitbucket.org/XXXX
will automatically call the one defined heregit clone ssh://git@bitbucket.org/XXXX
时会自动调用这里定义的ProxyCommand
phpcn_u15822017-05-02 09:35:57
Configure a proxy-wrapper
script
bash cat > $HOME/bin/proxy-wrapper #!/bin/bash nc -x127.0.0.1:7080 -X5 $*
Add executable permissions to it
bash $ chmod +x $HOME/bin/proxy-wrapper
Configuration .ssh/config
, set a proxy command for github.com
bash Host github github.com Hostname github.com User git ProxyCommand $HOME/bin/proxy-wrapper '%h %p'
Must use ssh protocol
bash $ git clone git@github.com:jjrdn/node-open.git
For the git protocol, please refer to [Using GIT through a SOCKS proxy](http://twopenguins.org/tips/git-throu...).
滿天的星座2017-05-02 09:35:57
Based on 1L’s answer, I wrote a smart_switcher, which can automatically identify and set various proxies. Based on http proxy configuration, it is especially suitable for various switching situations where the office has a proxy and there is no proxy at home. However, it is simplified to super simple, just set up your Just the gateway IP and Port.
ReadMe here. . .
A auto-detect proxy switcher fot http, https, ftp, rsync, ssh, git protocols.
A smart proxy switcher wrapper, supports http, https, ftp, rsync, ssh(connect depanded), git(connect depanded) protocols. It can automatically detect your network environment and set proxy for you.
If you usually switch the network environment (maybe home with no-proxy and workplace with proxy), it may help you a lot.
Tested in zsh and bash.
Simply source it in your .zshrc, or any shell script resource file like this:
source /path/to/smart_switcher.sh
and, make sure set your proxy_server/gateway in smart_switcher.sh
.
Normally, it executes antomatically when you log in.
smart_switcher
supports cecho, who will bring some colors for you.
connect is required if proxy is supported in ssh and git. You can install it easily in path /usr/bin/connect
.
怪我咯2017-05-02 09:35:57
The git protocol connection method uses ssh to communicate with the server. Setting ssh to use the sock5 proxy to connect to the server also solves the git proxy problem.
1.
https://raw.githubusercontent.com/bronzeee/ssh_connect/master/connect.c
Compile the above code using gcc and save it in the environment variable directory and rename it connect
Enter the .ssh directory and create a new one
File config
Host *
User git
ProxyCommand $HOME/.ssh/proxy-wrapper '%h %p'
File proxy-wrapper
#!/bin/bash
~/connect.exe -S http://IP:PORT $@
天蓬老师2017-05-02 09:35:57
There are many answers above. Assume that the program runs git commands without state or working directory, using -c
参数可以在运行时重载git配置,包括关键的http.proxy
For example:
git clone -c http.proxy=http://192.168.117.131:8888 http://github.com/me/test1.git
高洛峰2017-05-02 09:35:57
The best solution is proxychains (https://github.com/haad/proxychains).
The following command runs the program
$ proxychains program
It forces TCP connections initiated by a given program to go through a pre-configured proxy. At least on Linux, it's more versatile than "SOCKS proxy to HTTP proxy". The two complement each other and can cover all scenarios requiring agency.
Take Git as an example. Without proxychains, you must set up a proxy for each protocol (http, git, ssh) according to the requirements of the git documentation. The process is complicated and unstable. With proxychains, you can forget all this!
$ sudo apt-get install proxychains
Open /etc/proxychains.conf and comment out the following line (disable remote DNS resolution. There is a risk of DNS pollution. The following describes how to solve the problem of enable not working.)
proxy_dns
Finally add the following line:
socks5 134.64.206.85 1081
$ proxychains git clone git://github.com/yuzhichang/cppdep
$ sudo proxychains apt-get update
Here 134.64.206.85:1081 is the SOCKS proxy location.