【git】 ssh拉代码,为何出现timeout链接超时?

原因:
1.公司屏蔽了端口22的访问,检测一下端口22是否能够链接?
2.本机防火墙的缘故而不能使用端口22?

windows下检测端口是否能够访问?

PowerShell 版本是5及其以后,直接使用命令Get-NetTCPConnection参看与端口相关的信息


PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.693
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.693
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\> Get-NetTCPConnection -LocalPort 80 | Format-Table -Property LocalAddress, LocalPort, State, OwningProcess

LocalAddress LocalPort  State OwningProcess
------------ ---------  ----- -------------
::                  80 Listen             4

使用命令use Test-NetConnection测试远程主机的端口

PS C:\> Test-NetConnection -ComputerName 10.216.25.35 -Port 443 -InformationLevel Detailed

ComputerName            : 10.216.25.35
RemoteAddress           : 10.216.25.35
RemotePort              : 443
NameResolutionResults   : 10.216.25.35
MatchingIPsecRules      :
NetworkIsolationContext : Private Network
InterfaceAlias          : Ethernet
SourceAddress           : 10.61.39.173
NetRoute (NextHop)      : 10.61.36.1
TcpTestSucceeded        : True

如果是公司屏蔽端口访问,则使用http进行访问,对于git的url进行覆写。

git config --global url."https://".insteadOf git://
git config --list

~/.gitconfig 文件中可以看到:

[url "https://"]
   insteadOf = git://

因为防火墙的缘故22不能被使用,那换443

先测试443能不能用?

 $ ssh -T -p 443 [email protected]
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

~/.ssh/config文件下设置:

Host github.com
  Hostname ssh.github.com
  Port 443

测试是否设置成功

$ ssh -T [email protected]
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.

你可能感兴趣的:(git)