SSH git 克隆超时



请帮忙

我正在尝试通过 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 远程添加与其他 SSH 端口

Git 在自定义 SSH 端口上

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

简而言之,您无法更改远程服务正在侦听的端口。您正在尝试将非默认端口12345与 github.com 一起使用 这不会飞。在/etc/ssh/sshd_config中更改内容在这里也完全无关紧要。它会改变sshd的行为(即,如果有人试图对您的计算机进行ssh或git@ssh(。

顺便说一句,你可以测试你的ssh连接到github与github,这个单行:

ssh -T git@github.com

请注意,任何非默认端口都将挂起连接(ssh -T git@github.com -p 12345(

首先,如果你想考虑你的 ~/.ssh/config,你的 SSH URL 应该是

github.com:username/project-web.git

(没有git@,没有:12345(

第二个 12345 仅适用于反向代理,然后反向代理将重定向到端口 22 或 443(当"通过 HTTPS 端口使用 SSH"时(。
对于端口 443,主机名将ssh.github.com

最新更新