【发布时间】:2020-04-18 09:43:05
【问题描述】:
请帮忙
我正在尝试通过 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 with other SSH port
我做错了什么?我使用了错误的命令吗?我已经尝试了上面相关答案中的许多命令,仍然没有运气。
【问题讨论】:
-
注意
git!=github--github是一个使用git协议的云服务。您正在尝试连接到端口 12345 上的github.com,正如我所料,该端口超时。您要从“linux 服务器”连接到github还是从另一个工作站连接到“linux 服务器”? -
@karmakaze 是的,我正在使用
github,我理解那部分。我只是想通过另一个端口通过 SSH 使用git和github。克隆、拉取、结帐等。我的~/ssh/config文件可能有问题吗? -
我知道
github.com上没有设置可以让您选择连接到他们服务的端口。它始终是 https(端口 443)或 ssh(端口 22)。 -
换句话说,当你敲 GitHub 的门,他们说“谁是谁”,你说“端口 12345”时,他们说“走开,我们不喜欢你”。您必须先说“端口 22”。在端口 22 上阻止 inbound 连接是完全可以的;不要阻止 outbound 端口,并且在与 GitHub 通信时不要尝试使用不同的端口。
-
请注意,在非标准端口上运行您自己的入站 ssh 服务器很好,并为您提供一些次要优势,但不会为您提供大量安全性:运行端口扫描器的人可以看到您的系统在该端口上响应,然后可以探测以查看该端口上可能运行的内容,并确定它是一个 ssh 服务器。