Skip to content

Instantly share code, notes, and snippets.

@supersheep
Forked from kaelzhang/git-ssh-proxy.md
Created October 21, 2013 06:33
Show Gist options
  • Save supersheep/7079499 to your computer and use it in GitHub Desktop.
Save supersheep/7079499 to your computer and use it in GitHub Desktop.

Git ssh config

嘛,最近 github 间歇式被墙,尼玛一到晚上加班的时候就给我抽风啊,完全没法干活了。

所以稍微整理了一下 ssh 设置。

首先,你还是需要一台国外的可以 ssh 的机器,或者 ssh 帐号的,否则,下面就不用看了 =。=

步骤

1. ssh

平时工作的时候,还是需要让 ssh 连接保持的。

# ssh -D <port> <username>@<server>
ssh -D 8989 user@11.1.11.1

2. 修改 ~/.ssh/config

增加类似设置:

Host github.com
     HostName           github.com
     User               Kael
     IdentityFile       ~/.ssh/id_rsa
     IdentitiesOnly     yes
     ProxyCommand       ~/.socks5-proxywrapper %h %p

其中,UserIdentityFile 根据你的实际情况填写.

3. ~/.socks5-proxywrapper

创建该文件,并且内容为:

#!/bin/bash

connect -S 127.0.0.1:8989 "$@"

其中,端口为你 ssh -D 的端口

4. 安装 connect

下载 connect 的代码,注释掉 1765 行,编译

gcc connect.c -o connect

# 根据实际情况,cp 到你的 $PATH 目录
sudo cp connect /usr/local/bin

HTTP 协议

在 ~/.gitconfig 中添加

[http]
    proxy = socks5://127.0.0.1:8989

说明

  1. 仅支持 ssh 类型的 git remote 地址(~/.gitconfig 的 http proxy 配置起来很疼,不想去折腾了)
  2. 不影响连接内网的 git 服务器(根据实际情况增加新的 Host)
  3. 平时可以白天都挂着 ssh
  4. 如果远程经常断开,可以在 ~/.ssh/config 设置 ServerAliveInterval 参数
  5. 本来想写个一键安装脚本的,嘛,自己都折腾好了,懒得写了。
  6. 参考
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment