ssh 连接超时

SAR*_*SYR 6 linux git ssh github gitlab

我无法在 git 中 ssh 到 github、bitbucket 或 gitlab。
我通常会收到以下错误消息:如何避免它?

==========输出============

ssh -T git@github.com -i ~/.ssh/id_rsa -v
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.255.113] port 22.
debug1: connect to address 192.30.255.113 port 22: Connection timed out
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: connect to address 192.30.255.112 port 22: Connection timed out
ssh: connect to host github.com port 22: Connection timed out
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 0

此错误消息的典型情况是

  • 远程 ssh 守护进程未运行(GitHub、BitBucket 或 GitLab 的情况并非如此)
  • 本地端口 22 被阻止用于传出连接(在企业中工作时通常会出现这种情况:仅打开 http(s),而不打开 ssh)

OP 确认 ISP 已阻止端口 22。

看看是否可以使用 https 网址来代替:

cd /path/to/my/local/repo
git remote set-url origin https://github.com/<user>/<repo>
Run Code Online (Sandbox Code Playgroud)

请注意,使用trystack,您可能需要遵循这个要点

单击安全组选项卡,单击编辑规则,然后添加几个规则:

imcp, from port: -1, to port: -1, cidr: 0.0.0.0/0
tcp, from port: 22, to port: 22, cidr: your.ip.address.here/32
Run Code Online (Sandbox Code Playgroud)