ubuntu22.04通过ssh连接github时密钥匹配了却连接超时解决办法

最近在更新了本地代码 node 版本后,提交代码时报错如下

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

本以为是网络的问题或者被墙了,在确认本地 git 可以访问和几次尝试后依旧报这个错,查了各种资料,最后参考 git 官网给的解决办法(https://help.github.com/en/github/authenticating-to-github/using-ssh-over-the-https-port),使用 ssh 443端口

1. 先测试可用性
ssh -T -p 443 git@ssh.github.com
如果提示如下说明可用
Hi xiaoxin! You've successfully authenticated, but GitHub does not provide shell access.

2.然后编辑 ~/.ssh/config 文件,如果没有config文件的话就直接 vim ~/.ssh/config加入以下内容
Host github.com
Hostname ssh.github.com
Port 443

3.再次测试
ssh -T git@github.com
提示如下就说明成功。

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

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
连接 Github 可以使用 SSH 或 HTTPS 协议。以下是连接 Github 的步骤: 1. 首先,确保您已经在 GitHub 上创建了一个账户。 2. 打开终端,并安装 git:`sudo apt-get install git` 3. 生成 SSH 密钥:`ssh-keygen -t rsa -b 4096 -C "your_email@example.com"`,其中 "your_email@example.com" 是您的邮箱地址。 4. 在 GitHub 上添加公钥。在页面右上角点击头像,选择 "Settings",然后点击 "SSH and GPG keys",再点击 "New SSH key"。将您的公钥粘贴到 "Key" 字段中,然后点击 "Add SSH key"。 5. 验证 SSH 连接是否正常:`ssh -T git@github.com`。如果您第一次连接,会提示 "Are you sure you want to continue connecting (yes/no)?",输入 "yes" 并回车。如果连接正常,会输出 "Hi username! You've successfully authenticated, but GitHub does not provide shell access."。 6. 如果您选择使用 HTTPS 协议,可以在 GitHub 上创建一个 token。在页面右上角点击头像,选择 "Settings",然后点击 "Developer settings",再点击 "Personal access tokens",然后点击 "Generate new token"。在 "Note" 字段中输入一个名称,然后选择需要访问的权限,最后点击 "Generate token"。将生成的 token 保存在安全的地方。 7. 在终端中配置用户名和邮箱:`git config --global user.name "Your Name"` 和 `git config --global user.email "your_email@example.com"`。 8. 您现在可以将您的代码克隆到本地:`git clone git@github.com:username/repo.git` 或 `git clone https://github.com/username/repo.git`(如果使用 HTTPS 协议,则需要在 url 中加上 token)。 9. 提交修改:在本地修改代码后,使用 `git add` 命令将修改添加到暂存区,然后使用 `git commit` 命令提交修改。最后使用 `git push` 命令将修改推送到 GitHub。 希望以上步骤可以帮助到您。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值