给github设置代理

1 引言

本文详细介绍了在 Linux 环境下配置和使用网络代理的步骤。包括使用环境变量设置代理的方法、在 Git 中配置代理的常用方法以及一些调试工具。这些内容对于需要在网络受限环境下使用 Git 的用户非常实用。

2 配置代理

shell 复制代码
export http_proxy=http://host:port/  
export https_proxy=$http_proxy  
export ftp_proxy=$http_proxy  
export rsync_proxy=$http_proxy  
export all_proxy=$http_proxy  
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

3 git 设置 http 代理

最常用的访问 git 的方式是 http 方式,形如:

shell 复制代码
$ git clone https://github.com/xxx/yyy/

在这种情况下,正常连接需要设置 http proxy。

3.1 设置
shell 复制代码
$ git config --global http.proxy http://host:port
$ git config --global https.proxy https://host:port
3.2 查看当前配置
shell 复制代码
$ git config --global -l
3.3 取消代理
shell 复制代码
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy

4 设置 ssh 代理

我们也常常使用 ssh 方式操作 gihub 项目,形如:

shell 复制代码
git clone git@github.com:xxx/yyy.git

这种方式使用 ssh 与 github 建立连接,无法使用 http proxy 设置,具体设置方法如下:

shell 复制代码
$ vi ~/.ssh/config

编辑如下:

Host github.com
  HostName github.com
  User git
  ProxyCommand nc -x host:port %h %p

(注意:这里的 host:port 不是 http 代理,是 socks 代理)

测试 nc 命令是否正常

shell 复制代码
$ nc -x host:port github.com 22

测试 git 的 ssh 方式是否正常

shell 复制代码
$ ssh -T git@github.com
相关推荐
嘟嘟07171 小时前
手把手带你封装 Claude Code Skill:从会议纪要到 AI 日报,一套固定格式搞定所有自动化
github
嘟嘟07171 小时前
像水流一样——前端流式输出完整指南(3)
面试·github
半夜修仙3 小时前
Spring集成邮箱功能
java·开发语言·spring boot·spring·rabbitmq·github·maven
Esaka_Forever3 小时前
Prompting Techniques提示词工程核心知识梳理
人工智能·github
胡萝卜术12 小时前
深度重构:Agent Skills——从 Prompt 工程到能力工程
javascript·架构·github
csdn_aspnet16 小时前
GitHub Actions自动化运维实战,用CI/CD流水线实现测试、部署、安全扫描一体化
运维·安全·ci/cd·自动化·github
BerrySen17817 小时前
我的AI辅助开发工具链2026版
开源·github
dong_junshuai18 小时前
每天一个开源项目#40 Apache Ossie:1K Stars的AI/BI语义层通用标准
github
Lary_Rock18 小时前
MTK SecureBoot全链路配置指南
前端·vscode·github
逛逛GitHub20 小时前
终于有一个蒸馏 Apple 风格的 Skill 了,GitHub 上有 10.5K 人点赞。
github