使用 ssh 拉取 github 仓库有时会遇到这种错误:
$ git clone git@github.com:facebook/react.git
Cloning into 'react'...
ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
并且使用ssh -T git@github.com命令测试也是如此:
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Operation timed out
但是使用ssh -T -p 443 git@ssh.github.com命令可以成功:
$ ssh -T -p 443 git@ssh.github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
解决方案:
执行命令vim ~/.ssh/config创建配置文件,然后添加下面配置并保存:
Host github.com
Hostname ssh.github.com
Port 443
再次测试ssh -T git@github.com命令:
$ ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
再次克隆仓库:
$ git clone git@github.com:facebook/react.git
Cloning into 'react'...
remote: Enumerating objects: 213040, done.
remote: Counting objects: 100% (208/208), done.
remote: Compressing objects: 100% (104/104), done.
remote: Total 213040 (delta 145), reused 141 (delta 104), pack-reused 212832
Receiving objects: 100% (213040/213040), 183.45 MiB | 929.00 KiB/s, done.
Resolving deltas: 100% (152510/152510), done.