linux 命令行下设置代理;git命令设置代理;windows 系统下 git ssh 代理设置

当linux 代理软件设置好后,我们需要设置命令行代理的连接方式,这样在命令行中的软件才能使用:

设置http/https代理:

export https_proxy="127.0.0.1:12333"

export http_proxy="127.0.0.1:12333"

如果有密码:

export http_proxy_user=test
export http_proxy_pass=test

测试代理http/https:

curl http://www.google.com

curl https://www.google.com

当然我们也可以设置 proxychains-ng 进行设置代理:(推荐) 

apt install proxychains4 或者下载仓库代码进行编译;

vim /etc/proxychains4.conf 修改配置文件配置 socks5  127.0.0.1 1080 

测试:proxychains4 curl www.google.com 

这样支持tcp协议的软件也能进行使用了;

# 此种方案,适合使用 aaex 代理,electron-ssr 和 git 配合使用;用来使用github进行辅助开发; 

# git 命令设置代理 2021年1月21日

# 走socks5
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

# 走http 
git config --global http.proxy http://localhost:10809
git config --global https.proxy http://localhost:10809

# 涉及到文件
cat ~/.gitconfig

# 取消设置
git config --global --unset http.proxy
git config --global --unset https.proxy

# macos设置ssh;
Host github.com
    HostName github.com
    User git
    ProxyCommand nc -v -x localhost:10808 %h %p 

# 涉及 ~/.ssh/ssh_config 文件
可参考:https://github.com/yaowenxu/envfile/tree/master/ssh

# 2021年11月5日10:06:00:git windows 平台下,代理设置(基于connect 命令,7891为 clash 默认端口)

Host github.com
  HostName github.com
  User git
  ProxyCommand connect -S 127.0.0.1:7891 -a none %h %p

What is connect.exe? 

connect.c is a simple relaying command to make network connection via SOCKS and https proxy. It is mainly intended to be used as proxy command of OpenSSH. 
You can make SSH session beyond the firewall with this command,

Features of connect.c are:

Supports SOCKS (version 4/4a/5) and https CONNECT method.
Supports NO-AUTH and USERPASS authentication of SOCKS5
You can input password from tty, ssh-askpass or environment variable.
Run on UNIX or Windows platform.
You can compile with various C compiler (cc, gcc, Visual C, Borland C. etc.)
Simple and general program independent from OpenSSH.
You can also relay local socket stream instead of standard I/O.

# 2021年11月9日 13点02分:在与github desktop 配合使用的时候,需要指定connect.exe的路径:

Host github.com
  HostName github.com
  User git
  ProxyCommand "D:\\Git\\mingw64\\bin\\connect.exe" -S 127.0.0.1:7890 -a none %h %p

# 2021年12月7日 15点09分:今天在windows上使用的时候,代理突然就失灵了,Github Desktop变得巨卡,我重新改成了如下配置,可以参考:

Host github.com
  HostName github.com
  User git
  ProxyCommand "D:\Git\mingw64\bin\connect.exe" -S 127.0.0.1:7890 %h %p

# 2023年01月22日 19:52:30:fedora上使用 ssh 跳板,出现dump了文件,发现是因为nc命令选项变化,linux 上 nc -x 应该为 nc --proxy:

Host github.com
  HostName github.com
  User git
  ProxyCommand nc -v --proxy 127.0.0.1:7891 %h %p

保持更新,转载请注明出处;更多内容请关注 cnblogs.com/xuyaowen;

posted @ 2020-02-18 18:00  yaowenxu  阅读(9167)  评论(0编辑  收藏  举报