网络配置
网络配置 Git Git 的网络配置包括基于 http 协议和 ssh 协议,两者有不同的配置方法。 1. http 协议 通过git config命令进行。假设代理地址为http://proxy.exmaple.com:8080,配置命令如下: git config --global http.proxy http://proxy.example.com:8080 2. ssh 协议 SSH 配置稍微复杂一点,通常通过ssh-agent转发 SSH 密钥,或者通过设置代理服务器使用。最常见的方法是通过ProxyCommand配置来设置代理。 a. 使用ssh-agent转发 SSH 密钥 首先,启动ssh-agent并添加 SSH 密钥: eval $(ssh-agent -s) 然后在 Git 配置中在代理主机。 b. 配置.ssh/config文件使用代理 在~/.ssh/config文件中,配置以下内容: Host github.com Hostname github.com User git ProxyCommand nc -X connect -x proxy.example.com:8080 %h %p ProxyCommand使用nc(netcat)工具通过 HTTP/SOCKS 代理连接到 Git 服务器。-X connect表示使用 HTTP 代理,可以将connect替换为5或者4,分别表示使用 SOCKET5 和 SOCKET4 代理。-x proxy.example.com:8080指定代理地址和端口。 ...