当前位置:网站首页 > 更多 > 玩电脑 > 正文

[Linux学习] 解决 ssh: connect to host github.com port 22: Connection timed out

作者:CC下载站 日期:2022-04-18 00:00:00 浏览:54 分类:玩电脑

问题引入

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

[root@ydyno ~]# git clone [email protected]: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 [email protected]  
Hostname ssh.github.com  
PreferredAuthentications publickey  
IdentityFile ~/.ssh/id_rsa  
Port 443

修改文件权限

sudo chmod 600 config

再次 clone 发现已经没问题了

[root@ydyno ~]# git clone [email protected]: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

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯