解决 Git ssh 连接问题。

背景

ssh 正常配置的情况下 Git 无法连接 GitHub,如图

网络上的说法为端口 22 由于各种原因被封锁,需要更换端口。

解决方案

  1. 在 ssh 正常配置的情况下 cd ~/.ssh 进入 .ssh 文件夹
  2. touch config 新建 config 文件
  3. 在其中添加以下内容:
    1
    2
    3
    4
    5
    6
    Host github.com
    User GitHub 邮箱
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
  4. ssh -T git@github.com 测试一下

参考

github连接报”ssh: connect to host github.com port 22: Connection timed out”错误