解决 ssh: connect to host github.com port 22: Connection timed out

解决 ssh: connect to host github.com port 22: Connection timed out

知了小站
2022-04-18 / 0 评论 / 1,066 阅读

问题引入

当我在国内 Linux 机器上安装好 Git 环境后,将 github 代码克隆到 Linux 服务器出现了如下问题

[root@ydyno ~]# git clone git@github.com:elunez/**.git
正克隆到 '**'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决方法

进入 ~/.ssh 查看是否缺少 config 配置文件,如果缺少该配置文件那么使用如下命令创建

# 创建并写入文件数据
vi ~/.ssh/config
# 写入如下数据,User 填入注册时的邮箱
Host github.com  
User xxxxx@xx.com  
Hostname ssh.github.com  
PreferredAuthentications publickey  
IdentityFile ~/.ssh/id_rsa  
Port 443

修改文件权限

sudo chmod 600 config

再次 clone 发现已经没问题了

[root@ydyno ~]# git clone git@github.com:elunez/**.git
正克隆到 '**'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
^C收对象中:  35% (5/14), 2.67 MiB | 544.00 KiB/s 

参考:https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port#enabling-ssh-connections-over-https

本文共 122 个字数,平均阅读时长 ≈ 1分钟
0

打赏

评论 (0)

取消