问题

在 git push 时看到了这个信息

fatal: Could not read from remote repository.
Please make sure you have the correct access rights

一开始看到时,还以为又被墙了。但是github还能进。

试试能不能直接终端连接github

1
2
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out.

连接超时。看了网上,应该是端口的问题。

解决

在 ~/.ssh 目录里添加 config 文件。内容如下

1
2
3
4
5
6
Host github.com
User 你的邮箱
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

重新输入 ssh -T git@github.com

显示

1
2
3
The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

输入 yes,回车

1
2
Warning: Permanently added '[ssh.github.com]:443,[20.205.243.160]:443' (ECDSA) to the list of known hosts.
Hi jiaxu07! You've successfully authenticated, but GitHub does not provide shell access.

再执行 git push,一切正常。