通过公共WIFI连接Github(SSH),22端口被阻止

206

我目前正在使用公共WIFI,无法使用SSH(他们可能封锁了该端口)。然而,我需要该连接来进行git push

➜ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection refused

通过在端口80上设置SSH隧道并告诉github push使用该连接,是否可以绕过此限制?如何做到这一点?我使用的是OSX(lion)。 这一定是一个常见的问题吗?


有人知道如何在Launchpad.net上实现这个吗? - Anon
7个回答

436

6
@prtitrz 你有没有想法她在Heroku上的配置是什么? - Alextoul
45
只是提供信息,你不必使用vim打开文件。 - Joel Brewer
1
这很棒!但是我也需要在Heroku上做到这一点。有什么想法吗? - J-bob
2
谢谢!你的回答解决了我的问题,十年后! - Sean Yun-Shiuan Chuang
1
对我没用,仍然无法推送。 - Adrián Jaramillo
显示剩余4条评论

48
相同的方法也适用于Bitbucket:
Host bitbucket.org
  Hostname  altssh.bitbucket.org
  Port  443

通过 (已过时 / 失效)

通过, 已更新 (2015-10-29)


31

除了使用~/.ssh/config文件配置外,您还可以在使用远程URL时直接包含端口号。只需要:

  1. 使用类似ssh://user@host:port/path这样的正确格式的URL,而不是user@host:path的简写形式;以及

  2. github.com之前添加ssh.子域名。

例如,您可以将以下命令:

git@github.com:cdbennett/python-gitlab.git

使用

ssh://git@ssh.github.com:443/cdbennett/python-gitlab.git

这对我有效:ssh://git@ssh.github.com/repo.git,但是不要使用443端口,因为那会导致错误。 - Precious OSSAI
但是我只在项目目录上使用了 git config --local -e 命令。 - Precious OSSAI

10

对于GitLab,可以添加以下内容:

Host gitlab.com
  Hostname altssh.gitlab.com
  User git
  Port 443

来源:Gitlab SSH备用端口


2
不需要修改~/.ssh/config。你可以通过git remote add ..添加另一个远程仓库。
// github
git remote add ssh://git@ssh.github.com:443/repo/name.git

// gitlab
git remote add ssh://git@altssh.gitlab.com:443/repo/name.git

1

VPN(ExpressVPN)在JetBlue上对我有效


-2
我找到了两种方法。
第一种:
使用 tor 和 torify
成功在系统上安装和配置 Tor 后,只需运行这个命令来检查使用 Tor 的 SSH:
torify ssh -Tv git@gitlab.com

第二步

  • tor + privoxy + corkscrew

首先从头开始配置tor。 然后安装privoxy将tor SOCKS5转换为HTTP代理。

sudo apt install privoxy

接着安装corkscrew

sudo apt install corkscrew

将此配置文件放置在:~/.ssh/config

host *
    ProxyCommand corkscrew 127.0.0.1 8118 %h %p

或使用 ncat

Host gitlab.com
        User git
        ProxyCommand ncat --proxy 127.0.0.1:8118 %h %p

也可以使用nc代替ncat

    ProxyCommand nc --proxy 127.0.0.1:8118 %h %p

现在ssh可以使用配置的代理。

[编辑]

简化版本

在ssh命令前使用torify。

torify ssh -Tv git@gitlab.com


要使用Privoxy+Tor,可能需要更改默认配置。对于我来说,在/etc/privoxy/config中取消注释此行。

forward-socks5t   /               127.0.0.1:9050 .

ssh 配置

Host *
    ProxyCommand nc --proxy 127.0.0.1:8118 %h %p

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接