首页 > 解决方案 > ssh git clone 超时

问题描述

请帮忙

我正在尝试通过 SSH 与 linux ubuntu 服务器上的 git / github 进行通信,同时还有一个用于 SSH 的不同端口(不是 22 )。当我尝试时git clone,我正在使用这个命令:

$ git clone -v [git@github.com:12345]:username/project-web.git myfolder

它挂了大约 3 分钟,然后我得到这个输出:

Cloning into 'myfolder'...
ssh: connect to host github.com port 12345: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我的防火墙(UFW)设置正确;我可以成功 SSH 并连接到服务器。这是我的 UFW 配置:

22                         DENY        Anywhere
12345/tcp                  ALLOW       Anywhere
12345                      ALLOW       Anywhere
22/tcp                     DENY        Anywhere
22 (v6)                    DENY        Anywhere (v6)
12345/tcp (v6)             ALLOW       Anywhere (v6)
12345 (v6)                 ALLOW       Anywhere (v6)
22/tcp (v6)                DENY        Anywhere (v6)

这是我的~/.ssh/config文件:

Host github.com
    User git
    Hostname github.com
    IdentityFile ~/.ssh/deploy
    IdentitiesOnly yes
    Port 12345

和我的/etc/ssh/sshd_config文件:

...
Port 12345
...

我已经尝试了这些其他相关的 SO 答案,但仍然没有运气:

git remote add 与其他 SSH 端口

自定义 SSH 端口上的 Git

我究竟做错了什么?我使用了错误的命令吗?我已经尝试了上面相关答案中的许多命令,但仍然没有运气。

标签: gitgithubssh

解决方案


首先,如果您希望您的 ~/.ssh/config 被考虑在内,您的 SSH URL 应该是

github.com:username/project-web.git

(不git@,不:12345

第二个 12345 仅适用于反向代理,然后将重定向到端口 22 或 443(当“在 HTTPS 端口上使用 SSH ”时)。
关于端口 443,主机名将是ssh.github.com.


推荐阅读