Skip to content

Instantly share code, notes, and snippets.

@chenshengzhi
Last active August 11, 2024 11:18
Show Gist options
  • Save chenshengzhi/07e5177b1d97587d5ca0acc0487ad677 to your computer and use it in GitHub Desktop.
Save chenshengzhi/07e5177b1d97587d5ca0acc0487ad677 to your computer and use it in GitHub Desktop.
git ssh 代理设置

仅为 GitHub 设置代理

git 代理

设置 git config --global http.https://github.com.proxy socks5://127.0.0.1:1086
设置完成后, ~/.gitconfig 文件中会增加以下条目:

[http "https://github.com"]
    proxy = socks5://127.0.0.1:1086
ssh 代理

修改 ~/.ssh/config 文件

Host github.com
    User git
    ProxyCommand nc -v -x 127.0.0.1:1086 %h %p
@wanghuibin0
Copy link

$ ssh -T git@github.com
/usr/bin/bash: line 0: exec: nc: not found
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535

不行

好像你的系统里没有nc这个命令

@One010101
Copy link

One010101 commented Apr 28, 2021

$ ssh -T git@github.com
/ usr / bin / bash:第0行:exec:nc:找不到
kex_exchange_identification:连接被远程主机关闭
未知端口65535关闭了连接

不行

好像你的系统里没有nc这个命令

我找了网上很多教程,最后设置成功了,很简单,现在的git bash里面都包含了connect.exe这个软件,位置在bin下,你只要配置一个config可以了
vi ~/.ssh/config

ProxyCommand connect -S 127.0.0.1:10801 -a none %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

然后就可以使用ssh,测试方法是 ssh -T git@github.com,返回successful之类的就成功了

@wanghuibin0
Copy link

恭喜!

@MaxSecurity
Copy link

感谢很好使这办法。

@NewMai
Copy link

NewMai commented Jun 15, 2021

$ ssh -T git@github.com
/ usr / bin / bash:第0行:exec:nc:找不到
kex_exchange_identification:连接被远程主机关闭
未知端口65535关闭了连接

不行

好像你的系统里没有nc这个命令

我找了网上很多教程,最后设置成功了,很简单,现在的git bash里面都包含了connect.exe这个软件,位置在bin下,你只要配置一个config可以了
vi ~/.ssh/config

ProxyCommand connect -S 127.0.0.1:10801 -a none %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

然后就可以使用ssh,测试方法是 ssh -T git@github.com,返回successful之类的就成功了

看了无数文章,还是你的最给力

@lispon
Copy link

lispon commented Nov 9, 2021

以上处理方法, 应该区分 Windows 还是 Linux;

  • Linux下, 使用 nc 应该可以;

  • Windows下, 使用 connect.

@hokhu3
Copy link

hokhu3 commented Nov 21, 2021

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

@Q-kil
Copy link

Q-kil commented Dec 15, 2021

感谢🎉

@chenwaichung
Copy link

感谢分享

@Knit-zhang
Copy link

Knit-zhang commented Jul 25, 2022

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

感谢 🎉 , 终于解决了

@gmqiyue
Copy link

gmqiyue commented Aug 16, 2022

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

感谢 🎉 , 终于解决了

+1, it works!✌️

@Jackiexiao
Copy link

注意走 socks 和 https 是两个设置方案

Host github.com
  User git
  HostName ssh.github.com
  Port 443
  # 走 HTTP 代理, ubuntu 先 apt install -y socat
  ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=1080
  # 走 socks5 代理(如 Shadowsocks)
  # ProxyCommand nc -v -x 127.0.0.1:1080 %h %p

@bithaolee
Copy link

mac实测有用,感谢

@yeamu
Copy link

yeamu commented Dec 8, 2022

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

有用

@FantaZZ
Copy link

FantaZZ commented Dec 14, 2022

macos 好用 mark

@liubin95
Copy link

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

好用 +1

@rensss
Copy link

rensss commented Dec 22, 2022

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

Mac + clashx ssh 亲测有用

@SingleLyra
Copy link

it works, thx!

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

@x-zheng16
Copy link

ssh.github.com:443 seems to be faster. Work on Ubuntu 22.04. 7891 for Clash.

Host github.com
        Hostname ssh.github.com
        Port 443
        User git
        ProxyCommand nc -v -x  127.0.0.1:7891 %h %p

@miaozilong
Copy link

路由器上设置的魔法负载均衡 公网IP经常变,没办法 多试几次吧 每个公网IP都加入后 应该就好了

@Sped0n
Copy link

Sped0n commented May 17, 2023

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

感谢

@zhch-hong
Copy link

$ ssh -T git@github.com
/ usr / bin / bash:第0行:exec:nc:找不到
kex_exchange_identification:连接被远程主机关闭
未知端口65535关闭了连接

不行

好像你的系统里没有nc这个命令

我找了网上很多教程,最后设置成功了,很简单,现在的git bash里面都包含了connect.exe这个软件,位置在bin下,你只要配置一个config可以了 vi ~/.ssh/config

ProxyCommand connect -S 127.0.0.1:10801 -a none %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

然后就可以使用ssh,测试方法是 ssh -T git@github.com,返回successful之类的就成功了

有效,感谢

@godwinnnnn
Copy link

$ ssh -T git@github.com
/ usr / bin / bash:第0行:exec:nc:找不到
kex_exchange_identification:连接被远程主机关闭
未知端口65535关闭了连接

不行

好像你的系统里没有nc这个命令

我找了网上很多教程,最后设置成功了,很简单,现在的git bash里面都包含了connect.exe这个软件,位置在bin下,你只要配置一个config可以了 vi ~/.ssh/config

ProxyCommand connect -S 127.0.0.1:10801 -a none %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\One\.ssh\id_rsa"
  TCPKeepAlive yes

然后就可以使用ssh,测试方法是 ssh -T git@github.com,返回successful之类的就成功了
有效,感谢

@JESVN
Copy link

JESVN commented Sep 3, 2023

有可能会和gitlab有冲突,我是这样配置的就不影响gitlab:

Host github.com
  ProxyCommand connect -S 127.0.0.1:10808 -a none %h %p
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile ~/.ssh/id_rsa
  TCPKeepAlive yes
 

@FlameKm
Copy link

FlameKm commented Sep 15, 2023

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

十分感谢,这个方法有用,看了下给的链接,似乎是使用https的协议进行ssh连接,而刚好受代理服务器影响

@billchen2k
Copy link

帮忙了,之前还以为是 GitHub 的问题

@SheepTAO
Copy link

SheepTAO commented Oct 8, 2023

ssh over https提到域名改成ssh.github.com了

Host github.com
Hostname ssh.github.com
Port 443
User git

感谢,非常有用。

@zhufengning
Copy link

nc: invalid option -- 'x'

@zhufengning
Copy link

nc: invalid option -- 'x'

解决方法是:Looks like you have the "traditional" netcat (netcat-traditional) installed. The -x option is available in the OpenBSD netcat (netcat-openbsd). See also: What are the differences between netcat-traditional and netcat-openbsd? on Ask Ubuntu.

@songyule
Copy link

songyule commented Oct 18, 2023

ssh.github.com:443 seems to be faster. Work on Ubuntu 22.04. 7891 for Clash.

Host github.com
        Hostname ssh.github.com
        Port 443
        User git
        ProxyCommand nc -v -x  127.0.0.1:7891 %h %p

macos14.0 work!!! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment