ssh: connect to host github.com port 22: Operation timed out fatal: Could not read from remote repository

问题:

git推送到远程仓库发生错误

执行命令:

git push origin dev

发生错误:

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.

问题判断:

1、首先输入以下命令检查SSH是否能够连接成功

ssh -T git@github.com

发现报错:端口连接超时

ssh: connect to host github.com port 22: Operation timed out

 

解决方案:

找到.ssh文件夹,Mac中路径是 ~/.ssh,新建一个config文件,不带后缀

touch config

然后打开config文件,添加下列代码,注意User后面的邮箱改为你的邮箱

Host github.com
User xxx@163.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

再次执行下面代码

ssh -T git@github.com

会显示下面提示

The authenticity of host '[ssh.github.com]:443 ([20.200.200.100]:443)' can't be established.
ECDSA key fingerprint is SHA256:XXXXXXXX/XXXXXX/XXXXXXX.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443,[20.200.200.100]:443' (ECDSA) to the list of known hosts.

再次执行

ssh -T git@github.com

此时回应下面消息,说明成功了

Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

 

接下来就可以正常推送代码了

 

posted @ 2024-01-18 11:36  夜独醉  阅读(534)  评论(0)    收藏  举报