给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
相关推荐
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
程序视点1 天前
惊喜升级!Claude 3.7 Sonnet 上线 GitHub Copilot!已全账号开放!
github·claude·github copilot
今晚打老虎z1 天前
MailKit: 在 .NET 中实现高效电子邮件发送与接收
git·github·.net
架构文摘JGWZ1 天前
5个GitHub热点开源项目!!
学习·github·工具
液态不合群2 天前
DeepSeek “源神”启动!「GitHub 热点速览」
github
JNU freshman2 天前
github 推送的常见问题以及解决
git·github
cjchsh2 天前
ctfhub-web信息泄露通关攻略
windows·python·github
五行缺觉3282 天前
ROS ur10机械臂添加140夹爪全流程记录
c++·经验分享·机器人·github·ur机械臂·moveit!
無炆_2 天前
IDEA-插件开发踩坑记录-第五坑-没有飞机场导致无法访问GITHUB导致的讨厌问题
java·github·intellij-idea
cccccchd2 天前
github如何创建空文件夹
github